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

package entities;

import helper.LessonType;
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.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Szilárd
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Lesson.findType", query = "SELECT l FROM Lesson l WHERE l.lessonType = :lessonType AND l.currentSubjectId = :currentSubjectId"),
    @NamedQuery(name = "Lesson.findId", query = "SELECT l FROM Lesson l WHERE l.id = :id"),
    @NamedQuery(name = "Lesson.findBySemesterANDTeacher", query = "SELECT l FROM Lesson l WHERE l.currentSubjectId.semesterId = :semesterId AND l.teacherId = :teacherId"),
    @NamedQuery(name = "Lesson.updateInc", query = "UPDATE Lesson l SET l.registered = l.registered + 1 WHERE l.id = :id"),
    @NamedQuery(name = "Lesson.updateDec", query = "UPDATE Lesson l SET l.registered = l.registered - 1 WHERE l.id = :id")
})
public class Lesson 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;
    }

    @Enumerated
    @Column(name="TYPE")
    protected LessonType lessonType;

    public LessonType getLessonType() {
        return lessonType;
    }

    public void setLessonType(LessonType lessonType) {
        this.lessonType = lessonType;
    }

    @Column(name="LIMITED", length=20)
    protected int limit;

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    @Column(name="REGISTERED", length=20)
    protected int registered;

    public int getRegistered() {
        return registered;
    }

    public void setRegistered(int registered) {
        this.registered = registered;
    }

    @JoinColumn(name = "Teacher_Id", referencedColumnName = "ID")
    @ManyToOne
    private Users teacherId;

    public Users getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(Users teacherId) {
        this.teacherId = teacherId;
    }

    @JoinColumn(name = "CurrentSubject_Id", referencedColumnName = "Id")
    @ManyToOne
    private CurrentSubject currentSubjectId;

    public CurrentSubject getCurrentSubjectId() {
        return currentSubjectId;
    }

    public void setCurrentSubjectId(CurrentSubject currentSubjectId) {
        this.currentSubjectId = currentSubjectId;
    }

    @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 Lesson)) {
            return false;
        }
        Lesson other = (Lesson) 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.Lesson[id=" + id + "]";
    }

}
