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.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
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 com.rjconsultores.ventaboletos.enums.TipoAntifraude;

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

/**
 * @author Wilian
 */
@AuditarClasse(nome = "PtovtaAntifraude", tela = "auditarClasse.PtovtaAntifraude")
@Entity
@SequenceGenerator(name = "PTOVTA_ANTIFRAUDE_SEQ", sequenceName = "PTOVTA_ANTIFRAUDE_SEQ", allocationSize = 1)
@Table(name = "PTOVTA_ANTIFRAUDE")
public class PtovtaAntifraude implements Serializable , Auditavel<PtovtaAntifraude> {
	
    private static final long serialVersionUID = 1L;
    
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "PTOVTA_ANTIFRAUDE_SEQ")
    @Column(name = "PTOVTAANTIFRAUDE_ID")
    private Integer ptovtaAntifraudeId;
    
    @ManyToOne
    @JoinColumn(name = "PUNTOVENTA_ID")
    private PuntoVenta puntoventa;
    
    @ManyToOne
    @JoinColumn(name = "EMPRESA_ID")    
    private Empresa empresa;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "tipo")
    private TipoAntifraude tipo;
    
    @Column(name = "CHAVE")
    private String chave;
    
    @Column(name = "ACTIVO")
    private Boolean activo;
    
    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecmodif;
    
    @Column(name = "USUARIO_ID")
    private int usuarioId;
    
	@Transient
	@NaoAuditar
	private PtovtaAntifraude ptovtaAntifraudeClone;
   
    public PtovtaAntifraude() {
    	super();
    	this.activo = true;
    	this.fecmodif = new Date();
    }

    public PtovtaAntifraude(Integer ptovtaAntifraudeId) {
        this.ptovtaAntifraudeId = ptovtaAntifraudeId;
    }

	public Integer getPtovtaAntifraudeId() {
		return ptovtaAntifraudeId;
	}

	public void setPtovtaAntifraudeId(Integer ptovtaAntifraudeId) {
		this.ptovtaAntifraudeId = ptovtaAntifraudeId;
	}

	public PuntoVenta getPuntoventa() {
		return puntoventa;
	}

	public void setPuntoventa(PuntoVenta puntoventa) {
		this.puntoventa = puntoventa;
	}

	public Empresa getEmpresa() {
		return empresa;
	}

	public void setEmpresa(Empresa empresa) {
		this.empresa = empresa;
	}

	public TipoAntifraude getTipo() {
		return tipo;
	}

	public void setTipo(TipoAntifraude tipo) {
		this.tipo = tipo;
	}

	public String getChave() {
		return chave;
	}

	public void setChave(String chave) {
		this.chave = chave;
	}

	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 int getUsuarioId() {
		return usuarioId;
	}

	public void setUsuarioId(int usuarioId) {
		this.usuarioId = usuarioId;
	}

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

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof PtovtaAntifraude))
			return false;
		PtovtaAntifraude other = (PtovtaAntifraude) obj;
		if (ptovtaAntifraudeId == null) {
			if (other.ptovtaAntifraudeId != null)
				return false;
		} else if (!ptovtaAntifraudeId.equals(other.ptovtaAntifraudeId))
			return false;
		return true;
	}
	
	@Override
	public void clonar() throws CloneNotSupportedException {
		ptovtaAntifraudeClone = new PtovtaAntifraude();
		ptovtaAntifraudeClone = (PtovtaAntifraude) this.clone();
		Hibernate.initialize(ptovtaAntifraudeClone.getPuntoventa());
		
	}

	@Override
	public PtovtaAntifraude getCloneObject() throws CloneNotSupportedException {
		return ptovtaAntifraudeClone;
	}

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

    
}
