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.ConfRestricaoPtovta")
@SequenceGenerator(name = "CONF_RESTRICAO_PTOVTA_SEQ", sequenceName = "CONF_RESTRICAO_PTOVTA_SEQ", allocationSize = 1)
@Table(name = "CONF_RESTRICAO_PTOVTA")
public class ConfRestricaoPtovta implements Serializable, Auditavel<ConfRestricaoPtovta>{

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CONF_RESTRICAO_PTOVTA_SEQ")
	@Column(name = "CONFRESTRICAOPTOVTA_ID")
	private Integer confRestricaoPtovtaId;
	@JoinColumn(name = "CONFRESTRICAOCANALVENTA_ID", referencedColumnName = "CONFRESTRICAOCANALVENTA_ID")
	@ManyToOne
	private ConfRestricaoCanalVenta confRestricaoCanalVenta;
	@ManyToOne
	@JoinColumn(name = "PUNTOVENTA_ID", referencedColumnName = "PUNTOVENTA_ID")
	private PuntoVenta puntoVenta;
	@Column(name = "ACTIVO")
	private Boolean activo;
	@Column(name = "FECMODIF")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecmodif;
	@Column(name = "USUARIO_ID")
	private Integer usuarioId;
	@JoinColumn(name = "CONFRESTRICAOTRAMO_ID", referencedColumnName = "CONFRESTRICAOTRAMO_ID")
	@OneToOne
	private ConfRestricaoTramo confRestricaoTramo;
	@Transient
	@NaoAuditar
	private ConfRestricaoPtovta confRestricaoPtovtaClone; 

	public Integer getConfRestricaoPtovtaId() {
		return confRestricaoPtovtaId;
	}

	public void setConfRestricaoPtovtaId(Integer confRestricaoPtovtaId) {
		this.confRestricaoPtovtaId = confRestricaoPtovtaId;
	}

	public ConfRestricaoCanalVenta getConfRestricaoCanalVenta() {
		return confRestricaoCanalVenta;
	}

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

	public PuntoVenta getPuntoVenta() {
		return puntoVenta;
	}

	public void setPuntoVenta(PuntoVenta puntoVenta) {
		this.puntoVenta = puntoVenta;
	}

	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 ConfRestricaoTramo getConfRestricaoTramo() {
		return confRestricaoTramo;
	}

	public void setConfRestricaoTramo(ConfRestricaoTramo confRestricaoTramo) {
		this.confRestricaoTramo = confRestricaoTramo;
	}

	

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

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof ConfRestricaoPtovta)) {
			return false;
		}
		ConfRestricaoPtovta other = (ConfRestricaoPtovta) obj;
		if (activo == null) {
			if (other.activo != null) {
				return false;
			}
		} else if (!activo.equals(other.activo)) {
			return false;
		}
		if (confRestricaoTramo == null) {
			if (other.confRestricaoTramo != null) {
				return false;
			}
		} else if (!confRestricaoTramo.equals(other.confRestricaoTramo)) {
			return false;
		}
		if (puntoVenta == null) {
			if (other.puntoVenta != null) {
				return false;
			}
		} else if (!puntoVenta.equals(other.puntoVenta)) {
			return false;
		}
		return true;
	}

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

	@Override
	public ConfRestricaoPtovta getCloneObject() throws CloneNotSupportedException {
		return confRestricaoPtovtaClone;
	}

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