package models.eSecurePlay1;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.GenericGenerator;

import play.data.validation.Required;
import play.db.jpa.GenericModel;

@Entity
public class EsAuth extends GenericModel implements
		net.eclettica.esecure.models.EsAuth {
	
	
	
	@Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    public String uuid;
	
	
	
	@Required
	@Basic(optional = false)
	@Column(nullable = true)
	public String name;

	// @Column(columnDefinition = "TEXT")
	@Lob
	public String description;

	@ManyToMany(cascade = { CascadeType.DETACH })
	private Set<EsRole> roles = new HashSet<EsRole>();

	public Set<EsRole> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<EsRole> roles) {
		this.roles = roles;
	}

	public EsAuth() {
		this.name = "";
		this.description = "";
	}

	@Override
	public String getName() {
		return this.name;
	}

	public void setName(String name){
		this.name = name;
	}
	
	public void setDescription(String descrizione){
		this.description = descrizione;
	}
	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return this.description;
	}

	
	@Override
	public boolean equals(Object other) {
		if (!(other instanceof net.eclettica.esecure.models.EsAuth))
			return false;
		net.eclettica.esecure.models.EsAuth ot = (net.eclettica.esecure.models.EsAuth) other;
		return this.getName().equalsIgnoreCase(ot.getName());
	}

}
