package com.rjconsultores.ventaboletos.entidad;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.Hibernate;

import br.com.rjconsultores.auditador.annotations.AuditarClasse;
import br.com.rjconsultores.auditador.annotations.AuditarEntidade;
import br.com.rjconsultores.auditador.annotations.NaoAuditar;
import br.com.rjconsultores.auditador.interfaces.Auditavel;

@AuditarClasse(nome = "CategoriaOrgao", tela = "auditarClasse.CategoriaOrgao")
@Entity
@SequenceGenerator(name = "CATEGORIA_ORGAO_SEQ", sequenceName = "CATEGORIA_ORGAO_SEQ", allocationSize = 1)
@Table(name = "CATEGORIA_ORGAO")
public class CategoriaOrgao implements Serializable,  Auditavel<CategoriaOrgao> {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "CATEGORIA_ORGAO_SEQ")
    @Column(name = "CATEGORIAORGAO_ID")
    private Integer categoriaorgaoId;
    @Column(name = "ACTIVO")
    private Boolean activo;
    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecmodif;
    @Column(name = "USUARIO_ID")
    private Integer usuarioId;
    @JoinColumn(name = "ORGAOCONCEDENTE_ID", referencedColumnName = "ORGAOCONCEDENTE_ID")
    @ManyToOne
    @AuditarEntidade
    private OrgaoConcedente orgao;
    @JoinColumn(name = "CATEGORIACTRL_ID", referencedColumnName = "CATEGORIACTRL_ID")
    @ManyToOne
    private CategoriaCtrl categoriaCtrl;
    
	@Transient
	@NaoAuditar
	private CategoriaOrgao categoriaOrgaoClone;

    public CategoriaOrgao() {
    }

    public CategoriaOrgao(Integer categoriaorgaoId) {
        this.categoriaorgaoId = categoriaorgaoId;
    }

    

    public Integer getCategoriaorgaoId() {
		return categoriaorgaoId;
	}

	public void setCategoriaorgaoId(Integer categoriaorgaoId) {
		this.categoriaorgaoId = categoriaorgaoId;
	}

	public Boolean getActivo() {
        return activo;
    }

    public void setActivo(Boolean activo) {
        this.activo = activo;
    }

    public Date getFecmodif() {
        return fecmodif;
    }

    public void setFecmodif(Date fecmodif) {
        this.fecmodif = fecmodif;
    }

    public Integer getUsuarioId() {
        return usuarioId;
    }

    public void setUsuarioId(Integer usuarioId) {
        this.usuarioId = usuarioId;
    }

   

    public OrgaoConcedente getOrgao() {
		return orgao;
	}

	public void setOrgao(OrgaoConcedente orgao) {
		this.orgao = orgao;
	}

	public CategoriaCtrl getCategoriaCtrl() {
        return categoriaCtrl;
    }

    public void setCategoriaCtrl(CategoriaCtrl categoriaCtrl) {
        this.categoriaCtrl = categoriaCtrl;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CategoriaOrgao other = (CategoriaOrgao) obj;
        if (this.orgao != other.orgao && (this.orgao == null || !this.orgao.equals(other.orgao))) {
            return false;
        }
        if (this.categoriaCtrl != other.categoriaCtrl && (this.categoriaCtrl == null || !this.categoriaCtrl.equals(other.categoriaCtrl))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.orgao != null ? this.orgao.hashCode() : 0);
        hash = 97 * hash + (this.categoriaCtrl != null ? this.categoriaCtrl.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "com.rjconsultores.ventaboletos.entidad.CategoriaOrgao[categoriaorgaoId=" + categoriaorgaoId + "]";
    }

	@Override
	public void clonar() throws CloneNotSupportedException {
		
		categoriaOrgaoClone = new CategoriaOrgao();
		categoriaOrgaoClone = (CategoriaOrgao) this.clone();
		Hibernate.initialize(categoriaOrgaoClone.getOrgao());
		
	}

	@Override
	public CategoriaOrgao getCloneObject() throws CloneNotSupportedException {
		return categoriaOrgaoClone;
	}

	@Override
	public String getTextoInclusaoExclusao() {
		return String.format("ID [%s]", getOrgao().getDescOrgao()+"-"+getOrgao().getOrgaoConcedenteId());
	}
}
