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

package entities;

import helper.UserRole;
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="Users.findAll", query="SELECT u FROM Users u"),
    @NamedQuery(name="Users.findById", query="SELECT u FROM Users u WHERE u.id = :id"),
    @NamedQuery(name="Users.byUserName", query="SELECT u FROM Users u WHERE u.userName = :userName"),
    @NamedQuery(name="Users.findTeachers", query="SELECT u FROM Users u WHERE u.userRole = :userRole"),
    @NamedQuery(name="Users.update", query="UPDATE Users u SET u.name = :name, u.userName = :userName, u.password = :password, u.userRole = :userRole WHERE u.id= :userId")
})
public class Users 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="NAME", length=50)
    protected String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="USER_NAME", length=20)
    protected String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Column(name="PASSWORD", length=20)
    protected String password;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Enumerated
    @Column(name="USERROLE")
    protected UserRole userRole;

    public UserRole getUserRole() {
        return userRole;
    }

    public void setUserRole(UserRole userRole) {
        this.userRole = userRole;
    }

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

}
