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.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@SequenceGenerator(name="EMPRESA_CONTABANCARIA_SEQ", sequenceName="EMPRESA_CONTABANCARIA_SEQ", allocationSize=1)
@Table(name="EMPRESA_CONTABANCARIA")
public class EmpresaContaBancaria implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private Integer empresaContaBancariaId;
	private Empresa empresa;
	private InstiFinanceira instituicaoFinandeira;
	private String numConta;
	private String numAgencia;
	private String numIntegracion;
	private Boolean activo;
	private Date fecmodif;
	private Integer usuarioId; 
	
	@Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "EMPRESA_CONTABANCARIA_SEQ")
    @Column(name = "EMPRESACONTABANCARIA_ID")	
	public Integer getEmpresaContaBancariaId() {
		return empresaContaBancariaId;
	}
	
	public void setEmpresaContaBancariaId(Integer empresaContaBancariaId) {
		this.empresaContaBancariaId = empresaContaBancariaId;
	}
	
    @JoinColumn(name = "EMPRESA_ID", referencedColumnName = "EMPRESA_ID")
    @ManyToOne	
	public Empresa getEmpresa() {
		return empresa;
	}
    
	public void setEmpresa(Empresa empresa) {
		this.empresa = empresa;
	}
	
    @JoinColumn(name = "INSTIFINANCEIRA_ID", referencedColumnName = "INSTIFINANCEIRA_ID")
    @ManyToOne		
	public InstiFinanceira getInstituicaoFinandeira() {
		return instituicaoFinandeira;
	}
    
	public void setInstituicaoFinandeira(InstiFinanceira instituicaoFinandeira) {
		this.instituicaoFinandeira = instituicaoFinandeira;
	}
	
	@Column(name = "NUMCONTA")
	public String getNumConta() {
		return numConta;
	}
	
	public void setNumConta(String numConta) {
		this.numConta = numConta;
	}
	
	@Column(name = "NUMAGENCIA")
	public String getNumAgencia() {
		return numAgencia;
	}
	
	public void setNumAgencia(String numAgencia) {
		this.numAgencia = numAgencia;
	}

	@Column(name = "ACTIVO")
	public Boolean getActivo() {
		return activo;
	}

	public void setActivo(Boolean activo) {
		this.activo = activo;
	}

    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
	public Date getFecmodif() {
		return fecmodif;
	}

	public void setFecmodif(Date fecmodif) {
		this.fecmodif = fecmodif;
	}

	@Column(name = "USUARIO_ID")
	public Integer getUsuarioId() {
		return usuarioId;
	}

	public void setUsuarioId(Integer usuarioId) {
		this.usuarioId = usuarioId;
	}			
	
	@Column(name = "NUMINTEGRACION")
	public String getNumIntegracion() {
		return numIntegracion;
	}

	public void setNumIntegracion(String numIntegracion) {
		this.numIntegracion = numIntegracion;
	}

	@Override
	public boolean equals(Object old) {
		
        if (!(old instanceof EmpresaContaBancaria)) {
            return false;
        }
        
        EmpresaContaBancaria oldObject = (EmpresaContaBancaria) old;
        
        if(this.getInstituicaoFinandeira().equals(oldObject.getInstituicaoFinandeira()) && 
        		this.getNumAgencia().equals(oldObject.getNumAgencia()) && this.getNumConta().equals(oldObject.getNumConta()) &&
        		(this.getNumIntegracion() != null && this.getNumIntegracion().equals(oldObject.getNumIntegracion())) &&
        		this.getActivo().equals(oldObject.getActivo())) {
        	return true;
        }
        
        if(this.empresaContaBancariaId == null && oldObject.empresaContaBancariaId == null) {
        	return false;
        }
        
        if ((this.empresaContaBancariaId == null && oldObject.empresaContaBancariaId != null) || (this.empresaContaBancariaId != null && !this.empresaContaBancariaId.equals(oldObject.empresaContaBancariaId))) {
            return false;
        }
		
		return Boolean.TRUE;
	}
	
	@Override
	public String toString() {
		return getNumConta() + " - " + getNumAgencia() + " - " + getNumIntegracion() + " - " + getInstituicaoFinandeira().getNome();
	}
	
	@Override
    public int hashCode() {
        int hash = 0;
        hash += (empresaContaBancariaId != null ? empresaContaBancariaId.hashCode() : 0);
        return hash;
    }
}