/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.taxiservicios.beans.admin.client;

import com.arrebol.taxiservicios.beans.GenericPersonBean;
import com.arrebol.taxiservicios.controller.admin.CustomerController;
import com.arrebol.taxiservicios.model.admin.FinancingCustomer;
import com.arrebol.taxiservicios.model.admin.Taxi;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Named("customerFinantialDetailBean")
@ViewScoped
public class CustomerFinantialDetailBean extends GenericPersonBean implements Serializable {


    public List<FinancingCustomer> getDetails(String id) {
        logger.info("getDetails");
        try {
            setFinancing(getCustomerController().getFinancingByIdTaxi(id));

            logger.info("getDetails loaded size " + financing != null ? financing.size() : 0);
        } catch (Exception e) {
            logger.error("getDetails", e);
        }
        return null == financing ? new ArrayList<>() : financing;
    }
    
    @PostConstruct
    public void init() {
        try {
            loadBundlePropertyFile();

            setCustomerController(new CustomerController());
            setCustomerId(externalContext().getRequestParameterMap().get("selectedId"));
            setTaxi(getCustomerController().getTaxiByIdCustomer(getCustomerId(), getLoggedUser().getLocation().getId()));
            
        } catch (Exception e) {
            logger.error("Finantial customer init", e);
        }
    }

    private static final long serialVersionUID = -7284027390656669184L;

    final Logger logger = LogManager.getLogger(CustomerFinantialDetailBean.class);

    private CustomerController customerController;
    private String customerId;
    private List<Taxi> taxi;
    private List<FinancingCustomer> financing;
    private Taxi selectedTaxi;

    public List<FinancingCustomer> getFinancing() {
        return financing;
    }

    public void setFinancing(List<FinancingCustomer> financing) {
        this.financing = financing;
    }

    public Taxi getSelectedTaxi() {
        return selectedTaxi;
    }

    public void setSelectedTaxi(Taxi selectedTaxi) {
        this.selectedTaxi = selectedTaxi;
    }

    
    public List<Taxi> getTaxi() {
        return taxi;
    }

    public void setTaxi(List<Taxi> taxi) {
        this.taxi = taxi;
    }

    
    public String getCustomerId() {
        return customerId;
    }

    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }
   

    public CustomerController getCustomerController() {
        return customerController;
    }

    public void setCustomerController(CustomerController customerController) {
        this.customerController = customerController;
    }

  

}
