package com.rjconsultores.ventaboletos.entidad;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
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 org.hibernate.annotations.Where;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@Entity
@SequenceGenerator(name = "CONVENIO_TRANSPORTADORA_SEQ", sequenceName = "CONVENIO_TRANSPORTADORA_SEQ", allocationSize = 1)
@Table(name = "CONVENIO_TRANSPORTADORA")
public class ConvenioTransportadora {

	@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CONVENIO_TRANSPORTADORA_SEQ")    
    @Column(name = "CONVENIOTRANSPORTADORA_ID")
    private Long convenioTransportadoraId;

	@OneToOne
    @JoinColumn(name = "TRANSPORTADORA_ID")
    private Transportadora transportadora;

    @Column(name = "NOME_CONVENIO")
    private String nomeConvenio;

    @Column(name = "NUMCONVENIO")
    private String numConvenio;
    
    @Column(name = "VALOR")
    private BigDecimal valor;

    @Column(name = "TIPO_CONVENIO")
    private Integer tipoConvenio;

    @Column(name = "DATA_INICIAL")
    private Date dataInicial;

    @Column(name = "DATA_FINAL")
    private Date dataFinal;

    @Column(name = "USUARIO_ID")
    private Integer usuarioId;

    @Column(name = "ACTIVO")
    private boolean activo;

    @Column(name = "FECMODIF")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecModif;
    
    @OneToMany(mappedBy = "convenioTransportadora", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@Where(clause = "ACTIVO=1")
    private List<TarifaConvenioTransport> tarifasConvenio;

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