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 = "ConfRestricaoRutas", tela = "auditarClasse.ConfRestricaoRutas")
@SequenceGenerator(name = "CONF_REST_RUTAS_SEQ", sequenceName = "CONF_REST_RUTAS_SEQ", allocationSize = 1)
@Table(name = "CONF_REST_RUTAS")
public class ConfRestricaoRutas implements Serializable, Auditavel<ConfRestricaoRutas>{

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CONF_REST_RUTAS_SEQ")
	@Column(name = "CONFRESTRUTAS_ID")
	private Long confRestRutasId;
	
	@OneToOne
	@JoinColumn(name = "RUTA_ID")
	private Ruta ruta;
	
	@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 ConfRestricaoRutas confRestricaoRutasClone;
	
	public ConfRestricaoRutas() {
		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 getConfRestRutasId() {
		return confRestRutasId;
	}

	public void setConfRestRutasId(Long confRestRutasId) {
		this.confRestRutasId = confRestRutasId;
	}

	public ConfRestricaoCanalVenta getConfRestricaoCanalVenta() {
		return confRestricaoCanalVenta;
	}

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

	public Ruta getRuta() {
		return ruta;
	}

	public void setRuta(Ruta ruta) {
		this.ruta = ruta;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ruta == null) ? 0 : ruta.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;
		ConfRestricaoRutas other = (ConfRestricaoRutas) obj;
		if (ruta == null) {
			if (other.ruta != null)
				return false;
		} else if (!ruta.equals(other.ruta))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ConfRestricaoRutas [confRestRutasId=" + confRestRutasId + ", ruta=" + ruta + ", confRestricaoCanalVenta=" + confRestricaoCanalVenta + ", activo=" + activo + ", fecmodif=" + fecmodif + ", usuarioId=" + usuarioId + "]";
	}
	@Override
	public void clonar() throws CloneNotSupportedException {
		
		confRestricaoRutasClone = new ConfRestricaoRutas();
		confRestricaoRutasClone = (ConfRestricaoRutas) this.clone();
		Hibernate.initialize(confRestricaoRutasClone.getConfRestricaoCanalVenta());
		
	}
	@Override
	public ConfRestricaoRutas getCloneObject() throws CloneNotSupportedException {
		return confRestricaoRutasClone;
	}

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