/*
 * Copyright (c) 2011, Patrik Dufresne. All rights reserved.
 * Patrik Dufresne PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.planimod.core;

import java.util.Collection;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import org.hibernate.annotations.IndexColumn;

import com.patrikdufresne.managers.ManagedObject;

@Entity
public class EmployeePreference extends ManagedObject {

	/**
	 * Employee property
	 */
	public static final String EMPLOYEE = "employee"; //$NON-NLS-1$
	/**
	 * Preferred position property
	 */
	public static final String PREFERRED_POSITION = "preferredPosition"; //$NON-NLS-1$
	/**
	 * Preferred position shift property
	 */
	public static final String PREFERRED_POSITION_TEAM = "preferredPositionTeam"; //$NON-NLS-1$
	/**
	 * Preferred section
	 */
	public static final String PREFERRED_SECTION = "preferredSection"; //$NON-NLS-1$
	/**
	 * Preferred shifts property
	 */
	public static final String PREFERRED_TEAM = "preferredTeam"; //$NON-NLS-1$
	/**
	 * 
	 */
	private static final long serialVersionUID = -3366336520074905994L;

	/**
	 * The associated employee.
	 */
	private Employee employee;

	/**
	 * Define the preferred position.
	 * 
	 */
	private Position preferredPosition;
	/**
	 * Define the preferred position shifts.
	 */
	private Team preferredPositionTeam;

	private Section preferredSection;

	/**
	 */
	private List<Team> preferredTeam;

	@OneToOne(optional = false)
	public Employee getEmployee() {
		return this.employee;
	}

	/**
	 * Getter of the property <tt>preferredPosition</tt>
	 * 
	 * @return Returns the preferredPosition.
	 */
	@ManyToOne
	public Position getPreferredPosition() {
		return this.preferredPosition;
	}

	/**
	 * Returns the preferred position shifts.
	 * 
	 * @return
	 */
	@ManyToOne(fetch = FetchType.EAGER)
	public Team getPreferredPositionTeam() {
		return this.preferredPositionTeam;
	}

	/**
	 * Getter of the property <tt>section</tt>
	 * 
	 * @return Returns the section.
	 */
	@ManyToOne
	public Section getPreferredSection() {
		return this.preferredSection;
	}

	/**
	 * Getter of the property <tt>shift</tt>
	 * 
	 * @return Returns the shift.
	 */
	@ManyToMany(fetch = FetchType.EAGER)
	@IndexColumn(name = "`order`", nullable = false)
	public List<Team> getPreferredTeam() {
		return this.preferredTeam;
	}

	public void remove(final Collection<? extends Employee> s) {
		throw new UnsupportedOperationException();
	}

	public void setEmployee(Employee employee) {
		this.changeSupport.firePropertyChange(EMPLOYEE, this.employee,
				this.employee = employee);
	}

	/**
	 * Setter of the property <tt>preferredPosition</tt>
	 * 
	 * @param preferredPosition
	 *            The preferredPosition to set.
	 */
	public void setPreferredPosition(Position preferredPosition) {
		this.changeSupport.firePropertyChange(PREFERRED_POSITION,
				this.preferredPosition,
				this.preferredPosition = preferredPosition);
	}

	/**
	 * Sets the preferred position shifts.
	 * 
	 * @param prefferedPositionShift
	 */
	public void setPreferredPositionTeam(Team preferredPositionTeam) {
		this.changeSupport.firePropertyChange(PREFERRED_POSITION_TEAM,
				this.preferredPositionTeam,
				this.preferredPositionTeam = preferredPositionTeam);
	}

	/**
	 * Setter of the property <tt>preferredSection</tt>
	 * 
	 * @param preferredSection
	 *            The section to set.
	 */
	public void setPreferredSection(Section preferredSection) {
		this.changeSupport
				.firePropertyChange(PREFERRED_SECTION, this.preferredSection,
						this.preferredSection = preferredSection);
	}

	/**
	 * Setter of the property <tt>preferredTeam</tt>
	 * 
	 * @param preferredTeam
	 *            The team to set.
	 */
	public void setPreferredTeam(List<Team> preferredTeam) {
		this.changeSupport.firePropertyChange(PREFERRED_TEAM,
				this.preferredTeam, this.preferredTeam = preferredTeam);
	}

	@Override
	public String toString() {
		return "EmployeePreference [id=" + this.id //$NON-NLS-1$
				+ ", employee=" + this.employee + "]"; //$NON-NLS-1$ //$NON-NLS-2$
	}

}
