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

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CONF_REST_TRAMOOC_SEQ")
	@Column(name = "CONFRESTTRAMOOC_ID")
	private Long confRestTramoOCId;
	
	@OneToOne
	@JoinColumn(name = "ORIGEM_ID")
	private Parada origem;
	
	@OneToOne
	@JoinColumn(name = "DESTINO_ID")
	private Parada destino;
	
	@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 ConfRestricaoTramoOC confRestricaoTramoOCClone;
	
	public ConfRestricaoTramoOC() {
		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 ConfRestricaoCanalVenta getConfRestricaoCanalVenta() {
		return confRestricaoCanalVenta;
	}

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

	public Long getConfRestTramoOCId() {
		return confRestTramoOCId;
	}

	public void setConfRestTramoOCId(Long confRestTramoOCId) {
		this.confRestTramoOCId = confRestTramoOCId;
	}

	public Parada getOrigem() {
		return origem;
	}

	public void setOrigem(Parada origem) {
		this.origem = origem;
	}

	public Parada getDestino() {
		return destino;
	}

	public void setDestino(Parada destino) {
		this.destino = destino;
	}

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

	@Override
	public String toString() {
		return "ConfRestricaoTramoOC [confRestTramoOCId=" + confRestTramoOCId + ", origem=" + origem + ", destino=" + destino + ", confRestricaoCanalVenta=" + confRestricaoCanalVenta + ", activo=" + activo + ", fecmodif=" + fecmodif + ", usuarioId=" + usuarioId + "]";
	}
	
	@Override
	public void clonar() throws CloneNotSupportedException {
		
		confRestricaoTramoOCClone = new ConfRestricaoTramoOC();
		confRestricaoTramoOCClone = (ConfRestricaoTramoOC) this.clone();
		Hibernate.initialize(confRestricaoTramoOCClone.getConfRestricaoCanalVenta());
		
	}
	@Override
	public ConfRestricaoTramoOC getCloneObject() throws CloneNotSupportedException {
		return confRestricaoTramoOCClone;
	}

	@Override
	public String getTextoInclusaoExclusao() {
		return String.format("ID [%s]", getOrigem().getDescparada()+"-"+getDestino().getDescparada());
	}
}
