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.OneToOne;
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.NaoAuditar;
import br.com.rjconsultores.auditador.interfaces.Auditavel;

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

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CONF_REST_ORGAOCONCEDENTE_SEQ")
	@Column(name = "CONFRESTORGAOCONCEDENTE_ID")
	private Long confRestOrgaoConcedenteId;
	
	@OneToOne
	@JoinColumn(name = "ORGAOCONCEDENTE_ID")
	private OrgaoConcedente orgaoConcedente;
	
	@JoinColumn(name = "CONFRESTRICAOCANALVENTA_ID", referencedColumnName = "CONFRESTRICAOCANALVENTA_ID")
	@ManyToOne
	private ConfRestricaoCanalVenta confRestricaoCanalVenta;
	
	@Column(name = "ACTIVO")
	private Boolean activo;
	
	@Column(name = "FECMODIF")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecmodif;
	
	@Column(name = "USUARIO_ID")
	private Integer usuarioId;
	
	@Transient
	@NaoAuditar
	private ConfRestricaoOrgaoConcedente confRestricaoOrgaoConcedenteClone; 
	
	public ConfRestricaoOrgaoConcedente() {
		super();
	}

	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 Long getConfRestOrgaoConcedenteId() {
		return confRestOrgaoConcedenteId;
	}

	public void setConfRestOrgaoConcedenteId(Long confRestOrgaoConcedenteId) {
		this.confRestOrgaoConcedenteId = confRestOrgaoConcedenteId;
	}

	public OrgaoConcedente getOrgaoConcedente() {
		return orgaoConcedente;
	}

	public void setOrgaoConcedente(OrgaoConcedente orgaoConcedente) {
		this.orgaoConcedente = orgaoConcedente;
	}

	public ConfRestricaoCanalVenta getConfRestricaoCanalVenta() {
		return confRestricaoCanalVenta;
	}

	public void setConfRestricaoCanalVenta(ConfRestricaoCanalVenta confRestricaoCanalVenta) {
		this.confRestricaoCanalVenta = confRestricaoCanalVenta;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((orgaoConcedente == null) ? 0 : orgaoConcedente.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ConfRestricaoOrgaoConcedente other = (ConfRestricaoOrgaoConcedente) obj;
		if (orgaoConcedente == null) {
			if (other.orgaoConcedente != null)
				return false;
		} else if (!orgaoConcedente.equals(other.orgaoConcedente))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ConfRestricaoOrgaoConcedente [confRestOrgaoConcedenteId=" + confRestOrgaoConcedenteId + ", orgaoConcedente=" + orgaoConcedente + ", confRestricaoCanalVenta=" + confRestricaoCanalVenta + ", activo=" + activo + ", fecmodif=" + fecmodif + ", usuarioId=" + usuarioId + "]";
	}
	
	@Override
	public void clonar() throws CloneNotSupportedException {
		
		confRestricaoOrgaoConcedenteClone = new ConfRestricaoOrgaoConcedente();
		confRestricaoOrgaoConcedenteClone = (ConfRestricaoOrgaoConcedente) this.clone();
		Hibernate.initialize(confRestricaoOrgaoConcedenteClone.getConfRestricaoCanalVenta());
		
	}

	@Override
	public ConfRestricaoOrgaoConcedente getCloneObject() throws CloneNotSupportedException {
		return confRestricaoOrgaoConcedenteClone;
	}

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