package com.rjconsultores.ventaboletos.entidad;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
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.FetchType;
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;
import javax.persistence.Transient;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Where;

@Entity
@SequenceGenerator(name = "GP_PRICING_ESPECIFICO_SEQ", sequenceName = "GP_PRICING_ESPECIFICO_SEQ", allocationSize = 1)
@Table(name = "GP_PRICING_ESPECIFICO")
public class GP_PricingEspecifico implements Serializable, Cloneable {

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "GP_PRICING_ESPECIFICO_SEQ")
	@Column(name = "PRICINGESPECIFICO_ID")
	private Long pricingespecificoId;
	
	@Column(name = "NOMBPRICING")
	private String nombPricing;
	
	@Column(name = "FECHORINICIO")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fechorinicio;
	
	@Column(name = "FECHORFIN")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fechorfin;
	
	@Column(name = "TARIFA")
	private BigDecimal tarifa;
	
	@Column(name = "TARIFAREDABIERTO")
	private BigDecimal tarifaredabierto;
	
	@Column(name = "ACTIVO")
	private Boolean activo;
	
	@Column(name = "FECMODIF")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecmodif;
	
	@Column(name = "USUARIO_ID")
	private Integer usuarioId;
	
	@JoinColumn(name = "ORIGEN_ID", referencedColumnName = "PARADA_ID")
	@ManyToOne
	private Parada parada;
	
	@JoinColumn(name = "DESTINO_ID", referencedColumnName = "PARADA_ID")
	@ManyToOne
	private Parada parada1;
	
	@JoinColumn(name = "MONEDA_ID", referencedColumnName = "MONEDA_ID")
	@ManyToOne
	private Moneda moneda;
	
	@JoinColumn(name = "MARCA_ID", referencedColumnName = "MARCA_ID")
	@ManyToOne
	private Marca marca;
	
	@JoinColumn(name = "CLASESERVICIO_ID", referencedColumnName = "CLASESERVICIO_ID")
	@ManyToOne
	private ClaseServicio claseServicio;
	
	@Column(name = "CORRIDA_ID")
	private Integer corridaId;
	
	@Column(name = "EXIBEVENDA")
	private Boolean exibeVenda;
	
	@OneToMany(mappedBy = "pricingEspecifico", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private List<GP_PricingEspecificoOcupacion> pricingEspecificoOcupacionsList;
	
	@OneToMany(mappedBy = "pricingEspecifico", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@Where(clause="ACTIVO=1")
	private List<GP_PricingEspecificoAgencia> pricingEspecificoAgenciasList;
	
	@OneToMany(mappedBy = "pricingEspecifico", cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	@Where(clause="ACTIVO=1")
	private List<GP_PricingEspecificoCanalVendas> pricingEspecificoCanalVendasList;

	@OneToMany(mappedBy = "pricingEspecifico", cascade = CascadeType.ALL)
	@LazyCollection(LazyCollectionOption.FALSE)
	@Where(clause="ACTIVO=1")
	private List<GP_PricingEspecificoCategoria> pricingEspecificoCategoriaList;
	
	@Column(name = "COLOR")
	private String color;
	
	@Column(name = "INDSOBREPOSICAO")
	private Boolean indSobreposicao;

	public GP_PricingEspecifico() {
	}

	public GP_PricingEspecifico(Long pricingespecificoId) {
		this.pricingespecificoId = pricingespecificoId;
	}

	public Long getPricingespecificoId() {
		return pricingespecificoId;
	}

	public void setPricingespecificoId(Long pricingespecificoId) {
		this.pricingespecificoId = pricingespecificoId;
	}

	public Date getFechorinicio() {
		return fechorinicio;
	}

	public void setFechorinicio(Date fechorinicio) {
		this.fechorinicio = fechorinicio;
	}

	public Date getFechorfin() {
		return fechorfin;
	}

	public void setFechorfin(Date fechorfin) {
		this.fechorfin = fechorfin;
	}

	public BigDecimal getTarifa() {
		return tarifa;
	}

	public void setTarifa(BigDecimal tarifa) {
		this.tarifa = tarifa;
	}

	public BigDecimal getTarifaredabierto() {
		return tarifaredabierto;
	}

	public void setTarifaredabierto(BigDecimal tarifaredabierto) {
		this.tarifaredabierto = tarifaredabierto;
	}

	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 Parada getParada() {
		return parada;
	}

	public void setParada(Parada parada) {
		this.parada = parada;
	}

	public Parada getParada1() {
		return parada1;
	}

	public void setParada1(Parada parada1) {
		this.parada1 = parada1;
	}

	public Moneda getMoneda() {
		return moneda;
	}

	public void setMoneda(Moneda moneda) {
		this.moneda = moneda;
	}

	public Marca getMarca() {
		return marca;
	}

	public void setMarca(Marca marca) {
		this.marca = marca;
	}

	public ClaseServicio getClaseServicio() {
		return claseServicio;
	}

	public void setClaseServicio(ClaseServicio claseServicio) {
		this.claseServicio = claseServicio;
	}

	public String getNombPricing() {
		return nombPricing;
	}

	public void setNombPricing(String nombPricing) {
		this.nombPricing = nombPricing;
	}

	public Integer getCorridaId() {
		return corridaId;
	}

	public void setCorridaId(Integer corridaId) {
		this.corridaId = corridaId;
	}

	public List<GP_PricingEspecificoOcupacion> getPricingEspecificoOcupacionsList() {
		if(this.pricingEspecificoOcupacionsList == null){
			this.pricingEspecificoOcupacionsList = new ArrayList<GP_PricingEspecificoOcupacion>();
		}
		return this.pricingEspecificoOcupacionsList;
	}

	public void setPricingEspecificoOcupacionsList(List<GP_PricingEspecificoOcupacion> pricingEspecificoOcupacionsList) {
		this.pricingEspecificoOcupacionsList = pricingEspecificoOcupacionsList;
	}
	
	public Boolean getExibeVenda() {
		return exibeVenda;
	}

	public void setExibeVenda(Boolean exibeVenda) {
		this.exibeVenda = exibeVenda;
	}
	
	public List<GP_PricingEspecificoAgencia> getPricingEspecificoAgenciasList() {
		if(this.pricingEspecificoAgenciasList == null){
			this.pricingEspecificoAgenciasList = new ArrayList<GP_PricingEspecificoAgencia>();
		}
		return pricingEspecificoAgenciasList;
	}

	public void setPricingEspecificoAgenciasList(List<GP_PricingEspecificoAgencia> pricingEspecificoAgenciasList) {
		this.pricingEspecificoAgenciasList = pricingEspecificoAgenciasList;
	}
	

	public List<GP_PricingEspecificoCanalVendas> getPricingEspecificoCanalVendasList() {
		if(this.pricingEspecificoCanalVendasList == null){
			this.pricingEspecificoCanalVendasList = new ArrayList<GP_PricingEspecificoCanalVendas>();
		}
		return pricingEspecificoCanalVendasList;
	}

	public void setPricingEspecificoCanalVendasList(List<GP_PricingEspecificoCanalVendas> pricingEspecificoCanalVendasList) {
		this.pricingEspecificoCanalVendasList = pricingEspecificoCanalVendasList;
	}

	public List<GP_PricingEspecificoCategoria> getPricingEspecificoCategoriaList() {
		if (this.pricingEspecificoCategoriaList == null) {
			this.pricingEspecificoCategoriaList = new ArrayList<GP_PricingEspecificoCategoria>();
		}
		return pricingEspecificoCategoriaList;
	}

	public void setPricingEspecificoCategoriaList(List<GP_PricingEspecificoCategoria> pricingEspecificoCategoriaList) {
		this.pricingEspecificoCategoriaList = pricingEspecificoCategoriaList;
	}

	public Boolean getIndSobreposicao() {
		return indSobreposicao;
	}

	public void setIndSobreposicao(Boolean indSobreposicao) {
		this.indSobreposicao = indSobreposicao;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

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

	@Override
	public String toString() {
		return "[ nomePricing="+ nombPricing+ "] ";
	}
	
	@Transient
	public List<GP_PricingEspecificoOcupacion> getPricingEspecificoOcupacionsListActivos() {
		List<GP_PricingEspecificoOcupacion> peoList = new ArrayList<GP_PricingEspecificoOcupacion>();
		if(getPricingEspecificoOcupacionsList() != null) {
			for (GP_PricingEspecificoOcupacion peo : getPricingEspecificoOcupacionsList()) {
				if (peo.getActivo()) {
					peoList.add(peo);
				}
			}
		}
		return peoList;
	}
	@Transient
	public List<GP_PricingEspecificoAgencia> getPricingEspecificoAgenciaListActivos() {
		List<GP_PricingEspecificoAgencia> peoList = new ArrayList<GP_PricingEspecificoAgencia>();
		if(getPricingEspecificoAgenciasList() != null) {
			for (GP_PricingEspecificoAgencia peo : getPricingEspecificoAgenciasList()) {
				if (peo.getActivo()) {
					peoList.add(peo);
				}
			}
		}
		return peoList;
	}
	@Transient
	public List<GP_PricingEspecificoCanalVendas> getPricingEspecificoCanalListActivos() {
		List<GP_PricingEspecificoCanalVendas> pecList = new ArrayList<GP_PricingEspecificoCanalVendas>();
		if(getPricingEspecificoCanalVendasList() != null) {
			for (GP_PricingEspecificoCanalVendas pec : getPricingEspecificoCanalVendasList()) {
				if (pec.getActivo()) {
					pecList.add(pec);
				}
			}
		}
		return pecList;
	}
	
	public GP_PricingEspecifico clonar() throws CloneNotSupportedException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
		GP_PricingEspecifico novo = new GP_PricingEspecifico();
		
		novo = (GP_PricingEspecifico) super.clone();
		
		novo.setClaseServicio((ClaseServicio) this.claseServicio.clone());
		novo.setMarca((Marca) this.marca.clone());
		novo.setMoneda((Moneda) this.moneda.clone());
		novo.setParada((Parada) this.parada.clone());
		novo.setParada1((Parada) this.parada1.clone());
		
		novo.setPricingEspecificoAgenciasList(new ArrayList<GP_PricingEspecificoAgencia>());
		for(GP_PricingEspecificoAgencia  aux: pricingEspecificoAgenciasList) {
			
			GP_PricingEspecificoAgencia obj = (GP_PricingEspecificoAgencia) aux.clone();
			
			if(obj.getActivo()) {
				novo.getPricingEspecificoAgenciasList().add(obj);
			}
		}
		
		novo.setPricingEspecificoCanalVendasList(new ArrayList<GP_PricingEspecificoCanalVendas>());
		for(GP_PricingEspecificoCanalVendas  aux: pricingEspecificoCanalVendasList) {
			
			GP_PricingEspecificoCanalVendas obj = (GP_PricingEspecificoCanalVendas) aux.clone();
			
			if(obj.getActivo()) {
				novo.getPricingEspecificoCanalVendasList().add(obj);
			}
		}
		
		novo.setPricingEspecificoCategoriaList(new ArrayList<GP_PricingEspecificoCategoria>());
		for(GP_PricingEspecificoCategoria  aux: pricingEspecificoCategoriaList) {
			
			GP_PricingEspecificoCategoria obj = (GP_PricingEspecificoCategoria) aux.clone();
			
			if(obj.getActivo()) {
				novo.getPricingEspecificoCategoriaList().add(obj);
			}
		}
		
		novo.setPricingEspecificoOcupacionsList(new ArrayList<GP_PricingEspecificoOcupacion>());
		for(GP_PricingEspecificoOcupacion  aux: pricingEspecificoOcupacionsList) {
			
			GP_PricingEspecificoOcupacion obj = (GP_PricingEspecificoOcupacion) aux.clone();
			
			if(obj.getActivo()) {
				novo.getPricingEspecificoOcupacionsList().add(obj);
			}
		}
		
		return novo;
	}
}
