/*
 * 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.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
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.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Administrador
 */
@Entity
@SequenceGenerator(name = "CONVENIO_SEQ", sequenceName = "CONVENIO_SEQ", allocationSize = 1)
@Table(name = "CONVENIO")
public class Convenio implements Serializable {

    public static final Short IMPRIME_PRECO_TOTAL = 1;
    public static final Short IMPRIME_PRECO_MENOS_DESCONTO = 2;
    public static final Short IMPRIME_DESCONTO = 3;
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "CONVENIO_SEQ")
    @Basic(optional = false)
    @Column(name = "CONVENIO_ID")
    private Integer convenioId;
    
    @Column(name = "DESCCONVENIO")
    private String descconvenio;
    
    @Column(name = "ACTIVO")
    private Boolean activo;
    
    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecmodif;
    
    @Column(name = "USUARIO_ID")
    private Integer usuarioId;
    
    @Column(name = "CVECONVENIO")
    private String cveconvenio;
    
    @Column(name = "VALIDAFOLIO")
    private Boolean validafolio;
    
    @Column(name = "IMPRIMEPRECIO")
    private Short imprimeprecio;
    
    @OneToMany(mappedBy = "convenio", cascade = CascadeType.ALL)    
    private List<ConvenioDet> convenioDetList;
    
    @OneToMany(mappedBy = "convenio", cascade = CascadeType.ALL)
    private List<ConvenioTramo> convenioTramoList;
    
    @OneToMany(mappedBy = "convenio", cascade = CascadeType.ALL)
    private List<ConvenioUsuario> convenioUsuarioList;
    
    @OneToMany(mappedBy = "convenio", cascade = CascadeType.ALL)
    private List<ConvenioPuntoVenta> convenioPuntoVentaList;    
    
    @OneToMany(mappedBy = "convenio", cascade = CascadeType.ALL)
    private List<ConvenioEmpresa> convenioEmpresaList;
    
    @OneToMany(mappedBy = "convenio", cascade = CascadeType.ALL)
    private List<ConvenioRuta> convenioRutaList;
    
	@Column(name = "FECVENTAINI")
	@Temporal(TemporalType.TIMESTAMP)
    private Date fecVentaInicial;
	
	@Column(name = "FECVENTAFIN")
	@Temporal(TemporalType.TIMESTAMP)	
    private Date fecVentaFinal;
	
	@Column(name = "FECVIAJEINI")
	@Temporal(TemporalType.TIMESTAMP)	
    private Date fecViajeInicial;
	
	@Column(name = "FECVIAJEFIN")
	@Temporal(TemporalType.TIMESTAMP)		
    private Date fecViajeFinal;
	
	@Column(name = "INDDESCUENTONORMAL")
	private Integer indDescuentoNormal;

	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "CLIENTE_ID", referencedColumnName = "CLIENTE_ID")	
	private Cliente cliente;
	
	@Column(name = "INDGERAL")
	private Short indGeral;
	
	@Embedded
	private ConvenioCampanha convenioCampanha;
	
    public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public Convenio() {
    }

    public Convenio(Integer convenioId) {
        this.convenioId = convenioId;
    }

    public Integer getConvenioId() {
        return convenioId;
    }

    public void setConvenioId(Integer convenioId) {
        this.convenioId = convenioId;
    }

    public String getDescconvenio() {
        return descconvenio;
    }

    public void setDescconvenio(String descconvenio) {
        this.descconvenio = descconvenio;
    }

    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 String getCveconvenio() {
        return cveconvenio;
    }

    public void setCveconvenio(String cveconvenio) {
        this.cveconvenio = cveconvenio;
    }

    public Boolean getValidafolio() {
        return validafolio;
    }

    public void setValidafolio(Boolean validafolio) {
        this.validafolio = validafolio;
    }

    public Short getImprimeprecio() {
        return imprimeprecio;
    }

    public void setImprimeprecio(Short imprimeprecio) {
        this.imprimeprecio = imprimeprecio;
    }

    public List<ConvenioDet> getConvenioDetList() {
        List<ConvenioDet> tmp = new ArrayList<ConvenioDet>();
        if (convenioDetList != null) {
            for (ConvenioDet cd : this.convenioDetList) {
                if (cd.getActivo()) {
                    tmp.add(cd);
                }
            }
        }

        return tmp;
    }

    public void setConvenioDetList(List<ConvenioDet> convenioDetList) {
        this.convenioDetList = convenioDetList;
    }    
    
    public List<ConvenioTramo> getConvenioTramoList() {
    	List<ConvenioTramo> tempList = new ArrayList<ConvenioTramo>();
    	
    	if (convenioTramoList != null) {
    		for (ConvenioTramo convenioTramo : this.convenioTramoList) {
				if(convenioTramo.getActivo()) {
					tempList.add(convenioTramo);
				}
			}
    	}
    	
		return tempList;
	}        

	public List<ConvenioUsuario> getConvenioUsuarioList() {
		List<ConvenioUsuario> tempList = new ArrayList<ConvenioUsuario>();
		
		if (convenioUsuarioList != null) {
			for (ConvenioUsuario convenioUsuario : this.convenioUsuarioList) {
				if (convenioUsuario.getActivo()) {
					tempList.add(convenioUsuario);
				}
			}
		}

		return tempList;
	}	
	
	public List<ConvenioPuntoVenta> getConvenioPuntoVentaList() {
		List<ConvenioPuntoVenta> tempList = new ArrayList<ConvenioPuntoVenta>();
		
		if (convenioPuntoVentaList != null) {
			for (ConvenioPuntoVenta convenioPuntoVenta : this.convenioPuntoVentaList) {
				if (convenioPuntoVenta.getActivo()) {
					tempList.add(convenioPuntoVenta);
				}
			}
		}
		
		return tempList;
	}

	public void setConvenioPuntoVentaList(List<ConvenioPuntoVenta> convenioPuntoVentaList) {
		this.convenioPuntoVentaList = convenioPuntoVentaList;
	}

	public List<ConvenioEmpresa> getConvenioEmpresaList() {
		List<ConvenioEmpresa> tempList = new ArrayList<ConvenioEmpresa>();
		
		if (convenioEmpresaList != null) {
			for (ConvenioEmpresa convenioEmpresa : this.convenioEmpresaList) {
				if (convenioEmpresa.getActivo()) {
					tempList.add(convenioEmpresa);
				}
			}
		}
		
		return tempList;		
	}

	public List<ConvenioRuta> getConvenioRutaList() {
		List<ConvenioRuta> tempList = new ArrayList<ConvenioRuta>();
		
		if (convenioRutaList != null) {
			for (ConvenioRuta convenioRuta : this.convenioRutaList) {
				if (convenioRuta.getActivo()) {
					tempList.add(convenioRuta);
				}
			}
		}
		
		return tempList;	
	}

	public void setConvenioRutaList(List<ConvenioRuta> convenioRutaList) {
		this.convenioRutaList = convenioRutaList;
	}

	public void setConvenioEmpresaList(List<ConvenioEmpresa> convenioEmpresaList) {
		this.convenioEmpresaList = convenioEmpresaList;
	}

	public void setConvenioUsuarioList(List<ConvenioUsuario> convenioUsuarioList) {
		this.convenioUsuarioList = convenioUsuarioList;
	}

	public void setConvenioTramoList(List<ConvenioTramo> convenioTramoList) {
		this.convenioTramoList = convenioTramoList;
	}		

	public Date getFecVentaInicial() {
		return fecVentaInicial;
	}

	public void setFecVentaInicial(Date fecVentaInicial) {
		this.fecVentaInicial = fecVentaInicial;
	}

	public Date getFecVentaFinal() {
		return fecVentaFinal;
	}

	public void setFecVentaFinal(Date fecVentaFinal) {
		this.fecVentaFinal = fecVentaFinal;
	}

	public Date getFecViajeInicial() {
		return fecViajeInicial;
	}

	public void setFecViajeInicial(Date fecViajeInicial) {
		this.fecViajeInicial = fecViajeInicial;
	}

	public Date getFecViajeFinal() {
		return fecViajeFinal;
	}

	public void setFecViajeFinal(Date fecViajeFinal) {
		this.fecViajeFinal = fecViajeFinal;
	}

	public Integer getIndDescuentoNormal() {
		return indDescuentoNormal;
	}

	public void setIndDescuentoNormal(Integer indDescuentoNormal) {
		this.indDescuentoNormal = indDescuentoNormal;
	}
	
	public Short getIndGeral() {
		return indGeral;
	}

	public void setIndGeral(Short indGeral) {
		this.indGeral = indGeral;
	}


	public ConvenioCampanha getConvenioCampanha() {
		return convenioCampanha;
	}

	public void setConvenioCampanha(ConvenioCampanha convenioCampanha) {
		this.convenioCampanha = convenioCampanha;
	}

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

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Convenio)) {
            return false;
        }
        Convenio other = (Convenio) object;
        if ((this.convenioId == null && other.convenioId != null) || (this.convenioId != null && !this.convenioId.equals(other.convenioId))) {
            return false;
        }
        return true;
    }

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