/*
 * 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.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Rafius
 */
@Entity
@SequenceGenerator(name = "COMPANIA_BANCARIA_SEQ", sequenceName = "COMPANIA_BANCARIA_SEQ", allocationSize = 1)
@Table(name = "COMPANIA_BANCARIA")
public class CompaniaBancaria implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "COMPANIABANCARIA_ID")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "COMPANIA_BANCARIA_SEQ")
    private Integer companiabancariaId;
    @Column(name = "CVECOMPANIA")
    private String cvecompania;
    @Column(name = "CVESUCURSAL")
    private String cvesucursal;
    @Column(name = "USUARIO_ID")
    private Integer usuarioId;
    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecmodif;
    @Basic(optional = false)
    @Column(name = "ACTIVO")
    private Boolean activo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "companiaBancaria")
    private List<MerchantBancario> merchantBancarioList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "companiaBancaria")
    private List<UsuarioBancario> usuarioBancarioList;



    public CompaniaBancaria() {
    }

    public CompaniaBancaria(Integer companiabancariaId) {
        this.companiabancariaId = companiabancariaId;
    }

    public CompaniaBancaria(Integer companiabancariaId, Boolean activo) {
        this.companiabancariaId = companiabancariaId;
        this.activo = activo;
    }

    public Integer getCompaniabancariaId() {
        return companiabancariaId;
    }

    public void setCompaniabancariaId(Integer companiabancariaId) {
        this.companiabancariaId = companiabancariaId;
    }

    public String getCvecompania() {
        return cvecompania;
    }

    public void setCvecompania(String cvecompania) {
        this.cvecompania = cvecompania;
    }

    public String getCvesucursal() {
        return cvesucursal;
    }

    public void setCvesucursal(String cvesucursal) {
        this.cvesucursal = cvesucursal;
    }

    public Integer getUsuarioId() {
        return usuarioId;
    }

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

    public Date getFecmodif() {
        return fecmodif;
    }

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

    public Boolean getActivo() {
        return activo;
    }

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

    public List<MerchantBancario> getMerchantBancarioList() {
        List<MerchantBancario> tmp = new ArrayList<MerchantBancario>();
        if (merchantBancarioList != null) {
            for (MerchantBancario ddab : this.merchantBancarioList) {
                if (ddab.getActivo()) {
                    tmp.add(ddab);
                }
            }
        }

        this.merchantBancarioList = tmp;

        return tmp;
    }

    public void setMerchantBancarioList(List<MerchantBancario> merchantBancarioList) {
        this.merchantBancarioList = merchantBancarioList;
    }

    public List<UsuarioBancario> getUsuarioBancarioList() {
        List<UsuarioBancario> tmp = new ArrayList<UsuarioBancario>();
        if (usuarioBancarioList != null) {
            for (UsuarioBancario ddab : this.usuarioBancarioList) {
                if (ddab.getActivo()) {
                    tmp.add(ddab);
                }
            }
        }

        this.usuarioBancarioList = tmp;

        return tmp;
    }

    public void setUsuarioBancarioList(List<UsuarioBancario> usuarioBancarioList) {
        this.usuarioBancarioList = usuarioBancarioList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (companiabancariaId != null ? companiabancariaId.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 CompaniaBancaria)) {
            return false;
        }
        CompaniaBancaria other = (CompaniaBancaria) object;
        if ((this.companiabancariaId == null && other.companiabancariaId != null) || (this.companiabancariaId != null && !this.companiabancariaId.equals(other.companiabancariaId))) {
            return false;
        }
        return true;
    }

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