/*
 * 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.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
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.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

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

/**
 *
 * @author Administrador
 */
@Entity
@SequenceGenerator(name = "MARCA_SEQ", sequenceName = "MARCA_SEQ", allocationSize = 1)
@Table(name = "MARCA")
public class Marca implements Serializable, Auditavel<Marca> {

    public final static short TODOS = -1;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "MARCA_SEQ")
    @Column(name = "MARCA_ID")
    private Short marcaId;
    
    @Column(name = "DESCMARCA")
    private String descmarca;
    
    @OneToOne
    @JoinColumn(name = "EMPRESA_ID")
    private Empresa empresa;
    @Lob
    @Column(name = "LOGOTIPOMARCA")
    private byte[] logotipomarca;
    @Column(name = "ACTIVO")
    private Boolean activo;
    @Basic(optional = false)
    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecmodif;
    @Column(name = "USUARIO_ID")
    private Integer usuarioId;
    @OneToMany(mappedBy = "marca")
    @Fetch(FetchMode.SELECT)
    private List<CategoriaMarca> categoriaMarcaList;
    @OneToMany(mappedBy = "marca")
    @Fetch(FetchMode.SELECT)
    private List<ReservacionMarca> reservacionMarcaList;
    @OneToMany(mappedBy = "marca")
    private List<CancelacionCtrl> cancelacionCtrlList;
    @Column(name = "EQUIVALENCIA_ID")
    private String equivalenciaId;
    @OneToMany(mappedBy = "marca")
    @Fetch(FetchMode.SELECT)
    private List<TarifaHist> tarifaHistList;
    @OneToMany(mappedBy = "marca")
    @Fetch(FetchMode.SELECT)
    private List<Corrida> corridaList;
    
    @Transient
    @NaoAuditar
	private Marca marcaClone;

    public Marca() {
    }

    public Empresa getEmpresa() {
        return empresa;
    }

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

    public Marca(Short marcaId) {
        this.marcaId = marcaId;
    }

    public Marca(Short marcaId, Date fecmodif) {
        this.marcaId = marcaId;
        this.fecmodif = fecmodif;
    }

    public Marca(Short marcaId, String descMarca) {
        this.marcaId = marcaId;
        this.descmarca = descMarca;
    }
    
    public Marca(Short marcaId, String descMarca, Integer usuarioId , Date fecmodif) {
        this.marcaId = marcaId;
        this.descmarca = descMarca;
        this.usuarioId = usuarioId;
        this.fecmodif = fecmodif;
    }

    public Short getMarcaId() {
        return marcaId;
    }

    public void setMarcaId(Short marcaId) {
        this.marcaId = marcaId;
    }

    public String getDescmarca() {
        return descmarca;
    }

    public void setDescmarca(String descmarca) {
        this.descmarca = descmarca;
    }

    public byte[] getLogotipomarca() {
        return logotipomarca;
    }

    public void setLogotipomarca(byte[] logotipomarca) {
        this.logotipomarca = logotipomarca;
    }

    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 List<CategoriaMarca> getCategoriaMarcaList() {
        List<CategoriaMarca> tmp = new ArrayList<CategoriaMarca>();
        if (categoriaMarcaList != null) {
            for (CategoriaMarca cm : this.categoriaMarcaList) {
                if (cm.getActivo()) {
                    tmp.add(cm);
                }
            }
        }

        return tmp;
    }

    public void setCategoriaMarcaList(List<CategoriaMarca> categoriaMarcaList) {
        this.categoriaMarcaList = categoriaMarcaList;
    }

    public List<ReservacionMarca> getReservacionMarcaList() {
        List<ReservacionMarca> tmp = new ArrayList<ReservacionMarca>();
        for (ReservacionMarca rm : this.reservacionMarcaList) {
            if (rm.getActivo()) {
                tmp.add(rm);
            }
        }

        return tmp;
    }

    public void setReservacionMarcaList(List<ReservacionMarca> reservacionMarcaList) {
        this.reservacionMarcaList = reservacionMarcaList;
    }

    public List<CancelacionCtrl> getCancelacionCtrlList() {
        return cancelacionCtrlList;
    }

    public void setCancelacionCtrlList(List<CancelacionCtrl> cancelacionCtrlList) {
        this.cancelacionCtrlList = cancelacionCtrlList;
    }

    public String getEquivalenciaId() {
        return equivalenciaId;
    }

    public void setEquivalenciaId(String equivalenciaId) {
        this.equivalenciaId = equivalenciaId;
    }

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

    @Override
    public String toString() {
        return this.getDescmarca();
    }

    public List<Corrida> getCorridaList() {
        return corridaList;
    }

    public void setCorridaList(List<Corrida> corridaList) {
        this.corridaList = corridaList;
    }

    public List<TarifaHist> getTarifaHistList() {
        return tarifaHistList;
    }

    public void setTarifaHistList(List<TarifaHist> tarifaHistList) {
        this.tarifaHistList = tarifaHistList;
    }
    
	@Override
	public void clonar() throws CloneNotSupportedException {
		marcaClone = new Marca();
		marcaClone = (Marca) this.clone();
	}

	@Override
	public Marca getCloneObject() throws CloneNotSupportedException {
		return marcaClone;
	}
	
	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

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