package hr.fer.zemris.ffr.desktop.formCreator.model;

import hr.fer.zemris.ffr.desktop.formCreator.I18NUtil;

public class PMStudent implements Comparable<PMStudent> {
	
	private String jmbag;
	private String lastName;
	private String firstName;
	
	public PMStudent(String jmbag, String lastName, String firstName) {
		super();
		this.jmbag = jmbag;
		this.lastName = lastName;
		this.firstName = firstName;
	}
	
	public String getJmbag() {
		return jmbag;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public String getFirstName() {
		return firstName;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((jmbag == null) ? 0 : jmbag.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PMStudent other = (PMStudent) obj;
		if (jmbag == null) {
			if (other.jmbag != null)
				return false;
		} else if (!jmbag.equals(other.jmbag))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return lastName+", "+firstName+" ("+jmbag+")";
	}
	
	@Override
	public int compareTo(PMStudent o) {
		int r = I18NUtil.getSortingCollator().compare(this.lastName, o.lastName);
		if(r!=0) return r;
		r = I18NUtil.getSortingCollator().compare(this.firstName, o.firstName);
		if(r!=0) return r;
		return this.getJmbag().compareTo(o.jmbag);
	}
}
