package es.uv.saic.domain;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;


/**
 * The persistent class for the usuaris database table.
 * 
 */
@Entity
@Table(name="usuaris")
@NamedQuery(name="Usuari.findAll", query="SELECT u FROM Usuari u")
public class Usuari implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String usuari;

	private String clau;

	private String cognoms;

	private String email;

	private Boolean ldap;

	private String nom;
	
	@Column(name="data_ultim")
	private LocalDateTime dataUltim;
	
	private String locale;

	//bi-directional many-to-one association to InstanciaTasca
	@OneToMany(mappedBy="usuari")
	private List<InstanciaTasca> instanciesTasques;

	//bi-directional many-to-one association to UsuarisRol
	@OneToMany(mappedBy="usuari")
	private List<UsuarisRol> rols;
	
	@Transient
	private boolean isGranted;
	
	@Transient
	private boolean isAdmin;
	
	@Transient
	private boolean isDataTest;

	public Usuari() {
	}

	public String getUsuari() {
		return this.usuari;
	}

	public void setUsuari(String usuari) {
		this.usuari = usuari;
	}

	public String getClau() {
		return this.clau;
	}

	public void setClau(String clau) {
		this.clau = clau;
	}

	public String getCognoms() {
		return this.cognoms;
	}

	public void setCognoms(String cognoms) {
		this.cognoms = cognoms;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Boolean getLdap() {
		return this.ldap;
	}

	public void setLdap(Boolean ldap) {
		this.ldap = ldap;
	}

	public String getNom() {
		return this.nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}
	
	public LocalDateTime getDataUltim() {
		return this.dataUltim;
	}

	public void setDataUltim(LocalDateTime dataUltim) {
		this.dataUltim = dataUltim;
	}
	
	public String getLocale() {
		return this.locale;
	}
	
	public void setLocale(String locale) {
		this.locale = locale;
	}

	public List<InstanciaTasca> getInstanciesTasques() {
		return this.instanciesTasques;
	}

	public void setInstanciesTasques(List<InstanciaTasca> instanciaTascas) {
		this.instanciesTasques = instanciaTascas;
	}

	public InstanciaTasca addInstanciaTasca(InstanciaTasca instanciaTasca) {
		getInstanciesTasques().add(instanciaTasca);
		instanciaTasca.setUsuari(this);

		return instanciaTasca;
	}

	public InstanciaTasca removeInstanciaTasca(InstanciaTasca instanciaTasca) {
		getInstanciesTasques().remove(instanciaTasca);
		instanciaTasca.setUsuari(null);

		return instanciaTasca;
	}

	public List<UsuarisRol> getUsuarisRols() {
		return this.rols;
	}

	public void setUsuariRols(List<UsuarisRol> usuarisRols) {
		this.rols = usuarisRols;
	}

	public UsuarisRol addRol(UsuarisRol usuarisRol) {
		getUsuarisRols().add(usuarisRol);
		usuarisRol.setUsuari(this);

		return usuarisRol;
	}

	public UsuarisRol removeRol(UsuarisRol usuarisRol) {
		getUsuarisRols().remove(usuarisRol);
		usuarisRol.setUsuari(null);

		return usuarisRol;
	}
	
	public boolean isGranted() {
		return this.isGranted;
	}

	public void setGranted(boolean isGranted) {
		this.isGranted = isGranted;
	}
	public boolean isAdmin() {
		return this.isAdmin;
	}

	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}

	public boolean isDataTest() {
		return isDataTest;
	}

	public void setDataTest(boolean isDataTest) {
		this.isDataTest = isDataTest;
	}
	
	public boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		if (!(other instanceof Usuari)) {
			return false;
		}
		Usuari castOther = (Usuari)other;
		return 
			this.usuari.equals(castOther.usuari);
	}

	public int hashCode() {
		final int prime = 31;
		int hash = 17;
		hash = hash * prime + this.usuari.hashCode();
		
		return hash;
	}
	
}