package somiba.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

class YearTeamCompositeKey implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	private String original;
    private String custom;
	public String getOriginal() { return original; }
	public void setOriginal(String original) { this.original = original; }
	public String getCustom() { return custom; }
	public void setCustom(String custom) { this.custom = custom; }
}

@IdClass(YearTeamCompositeKey.class)
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name="yearTeam")
public class YearTeam {
    @Id @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumns ({
        @JoinColumn(name="original", referencedColumnName = "original"),
        @JoinColumn(name="custom", referencedColumnName = "custom"),
    })

	@Column(length = 9, nullable = false)  
	public String getOriginal() {
		return original;
	}

	public void setOriginal(String original) {
		this.original = original;
	}

	@Column(length = 9, nullable = false)  
	public String getCustom() {
		return custom;
	}

	public void setCustom(String custom) {
		this.custom = custom.toUpperCase();
	}

	@Id
	@Column(length = 4, nullable = false)  
	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year.toUpperCase();
	}

	@Id
	@Column(length = 4, nullable = false)  
	public String getTeam() {
		return team;
	}

	public void setTeam(String team) {
		this.team = team.toUpperCase();
	}

	String original;
	String custom;
	String year;
	String team;

	public YearTeam(String original, String custom, String year, String team) {
		this.original = original.toUpperCase();
		this.custom = custom.toUpperCase();
		this.year = year;
		this.team = team.toUpperCase();
	}

	public boolean equals(Object obj) {
		YearTeam candidate = (YearTeam) obj;
		return (candidate.getCustom().equals(custom) && candidate.getYear().equals(year) && candidate.getTeam().equals(team));
	}
}
