/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.utilerias.render;

import java.util.List;

import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

import com.rjconsultores.ventaboletos.entidad.GP_PricingEspecifico;
import com.rjconsultores.ventaboletos.entidad.GP_PricingEspecificoCategoria;
import com.rjconsultores.ventaboletos.entidad.PricingEspecifico;
import com.rjconsultores.ventaboletos.entidad.PricingEspecificoCategoria;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;

/**
 * 
 * @author Cássio Rocha
 */
public class RenderPricingEspecifico implements ListitemRenderer {

	public void render(Listitem lstm, Object o) throws Exception {
		if(o instanceof PricingEspecifico ) {
			PricingEspecifico pe = (PricingEspecifico) o;
	
			Listcell lc = new Listcell(pe.getPricingespecificoId().toString());
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getNombPricing() == null ? "" : pe.getNombPricing());
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getMarca().getDescmarca());
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getMoneda().getDescmoneda());
			lc.setParent(lstm);
	
			lc = new Listcell(categoriasToString(pe.getPricingEspecificoCategoriaList()));
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getClaseServicio().getDescclase());
			lc.setParent(lstm);
	
			lc = new Listcell(DateUtil.getStringDate(pe.getFechorinicio(), "dd/MM/yyyy HH:mm"));
			lc.setParent(lstm);
	
			lc = new Listcell(DateUtil.getStringDate(pe.getFechorfin(), "dd/MM/yyyy HH:mm"));
			lc.setParent(lstm);
	
			Integer corridaId = pe.getCorridaId();
			if (corridaId != null) {
				lc = new Listcell(corridaId.toString());
			} else {
				lc = new Listcell("");
			}
			lc.setParent(lstm);
	
			lstm.setAttribute("data", pe);
		} else {
			GP_PricingEspecifico pe = (GP_PricingEspecifico) o;
			
			Listcell lc = new Listcell(pe.getPricingespecificoId().toString());
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getNombPricing() == null ? "" : pe.getNombPricing());
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getMarca().getDescmarca());
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getMoneda().getDescmoneda());
			lc.setParent(lstm);
	
			lc = new Listcell(categoriasToStringGP(pe.getPricingEspecificoCategoriaList()));
			lc.setParent(lstm);
	
			lc = new Listcell(pe.getClaseServicio().getDescclase());
			lc.setParent(lstm);
	
			lc = new Listcell(DateUtil.getStringDate(pe.getFechorinicio(), "dd/MM/yyyy HH:mm"));
			lc.setParent(lstm);
	
			lc = new Listcell(DateUtil.getStringDate(pe.getFechorfin(), "dd/MM/yyyy HH:mm"));
			lc.setParent(lstm);
	
			Integer corridaId = pe.getCorridaId();
			if (corridaId != null) {
				lc = new Listcell(corridaId.toString());
			} else {
				lc = new Listcell("");
			}
			lc.setParent(lstm);
	
			lstm.setAttribute("data", pe);
		}
	}
	
	private String categoriasToString(List<PricingEspecificoCategoria> pricingEspecificoCategoriaList) {
		String result = "";

		for (PricingEspecificoCategoria p : pricingEspecificoCategoriaList) {
			result += p.getCategoria().getDesccategoria() + "-";
		}
		return result.isEmpty() ? "" : result.substring(0, result.length() - 1);
	}
	
	private String categoriasToStringGP(List<GP_PricingEspecificoCategoria> pricingEspecificoCategoriaList) {
		String result = "";

		for (GP_PricingEspecificoCategoria p : pricingEspecificoCategoriaList) {
			result += p.getCategoria().getDesccategoria() + "-";
		}
		return result.isEmpty() ? "" : result.substring(0, result.length() - 1);
	}
}
