/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import helper.SchoolYearState;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Szilárd
 */
@Entity
@NamedQueries({
    @NamedQuery(name="Semester.findAll", query="SELECT s FROM Semester s"),
    @NamedQuery(name="Semester.findById", query="SELECT s FROM Semester s WHERE s.id = :id"),
    @NamedQuery(name = "Semester.findOpenAndClosed", query = "SELECT s FROM Semester s WHERE s.schoolYearState = :state1 OR s.schoolYearState = :state2"),
    @NamedQuery(name = "Semester.findOpen", query = "SELECT s FROM Semester s WHERE s.schoolYearState = :state"),
    @NamedQuery(name = "Semester.update", query = "UPDATE Semester s SET s.schoolYearState = :schoolYearState WHERE s.id = :semesterId")
})
public class Semester implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="SCHOOLYEAR", length=20)
    protected String schoolYear;

    public String getSchoolYear() {
        return schoolYear;
    }

    public void setSchoolYear(String schoolYear) {
        this.schoolYear = schoolYear;
    }

    @Enumerated
    @Column(name="SCHOOLYEAR_STATES", length=20)
    protected SchoolYearState schoolYearState;

    public SchoolYearState getSchoolYearState() {
        return schoolYearState;
    }

    public void setSchoolYearState(SchoolYearState schoolYearState) {
        this.schoolYearState = schoolYearState;
    }

    public int getState(){
        int i = 0;
        if(this.schoolYearState.equals(SchoolYearState.CLOSED))
            i = 0;
        if(this.schoolYearState.equals(SchoolYearState.OPEN))
            i = 1;
        if(this.schoolYearState.equals(SchoolYearState.NEW))
            i = 2;
        return i;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Semester)) {
            return false;
        }
        Semester other = (Semester) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Semester[id=" + id + "]";
    }

}
