/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.entidad;

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

import javax.persistence.Basic;
import javax.persistence.CascadeType;
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.JoinColumns;
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 org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

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

/**
 * 
 * @author Wallace
 */
@Entity
@SequenceGenerator(name = "CORRIDA_INFO_SEQ", sequenceName = "CORRIDA_INFO_SEQ", allocationSize = 1)
@AuditarClasse(nome = "CorridaInfo", tela = "auditarClasse.CorridaInfo")
@Table(name = "CORRIDA_INFO")
public class CorridaInfo implements Serializable,  Auditavel<CorridaInfo> {

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@Column(name = "CORRIDAINFO_ID")
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CORRIDA_INFO_SEQ")
	private Integer corridaInfoId;
	
	@Column(name = "ACTIVO")
	private Boolean activo;

	@Column(name = "FECMODIF")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecmodif;
	@Column(name = "USUARIO_ID")
	private Integer usuarioId;
	
	@JoinColumn(name = "ORIGEN_ID", referencedColumnName = "PARADA_ID")
	@ManyToOne
	private Parada origem;
	@JoinColumn(name = "DESTINO_ID", referencedColumnName = "PARADA_ID")
	@ManyToOne
	private Parada destino;
	
	@Column(name = "INFOCORRIDA")
	private String infoCorrida;

	@OneToOne
	@NotFound(action = NotFoundAction.IGNORE)
	@JoinColumns({
			@JoinColumn(name = "CORRIDA_ID", referencedColumnName = "CORRIDA_ID"),
			@JoinColumn(name = "FECCORRIDA", referencedColumnName = "FECCORRIDA") })
	private Corrida corrida;

	@Transient
	@NaoAuditar
	private CorridaInfo corridaInfoClone;

	public CorridaInfo() {
	}

	public Integer getCorridaInfoId() {
		return corridaInfoId;
	}


	public void setCorridaInfoId(Integer corridaInfoId) {
		this.corridaInfoId = corridaInfoId;
	}


	public CorridaInfo getCorridaInfoClone() {
		return corridaInfoClone;
	}


	public void setCorridaInfoClone(CorridaInfo corridaInfoClone) {
		this.corridaInfoClone = corridaInfoClone;
	}


	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 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;
	}

	public String getInfoCorrida() {
		return infoCorrida;
	}

	public void setInfoCorrida(String infoCorrida) {
		this.infoCorrida = infoCorrida;
	}
	
	public Corrida getCorrida() {
		return corrida;
	}

	public void setCorrida(Corrida corrida) {
		this.corrida = corrida;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (getCorridaInfoId() != null ? getCorridaInfoId().hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		if (!(object instanceof CorridaInfo)) {
			return false;
		}
		CorridaInfo other = (CorridaInfo) object;
		if ((this.getCorridaInfoId() == null && other.getCorridaInfoId() != null) || (this.getCorridaInfoId() != null && !this.getCorridaInfoId().equals(other.getCorridaInfoId()))) {
			return false;
		}
		return true;
	}

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

	
	@Override
	public void clonar() throws CloneNotSupportedException {
		corridaInfoClone = new CorridaInfo();
		corridaInfoClone = (CorridaInfo) this.clone();
		Hibernate.initialize(corridaInfoClone.getCorrida());
	}

	@Override
	public CorridaInfo getCloneObject() throws CloneNotSupportedException {
		return corridaInfoClone;
	}

	@Override
	public String getTextoInclusaoExclusao() {
		return String.format("CorridaInfo - Origem [%s] - Destino [%s] - Informaaca [%s]",  getOrigem() != null ? getOrigem().getDescparada() : "",
				 getDestino() != null ? getDestino().getDescparada() : "", getInfoCorrida() != null ? getInfoCorrida() : "");
	}

}
