/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.taxiservicios.beans.banks;

import com.arrebol.taxiservicios.beans.catalog.*;
import com.arrebol.taxiservicios.beans.Datatable;
import com.arrebol.taxiservicios.beans.TaxiGenericBean;
import com.arrebol.taxiservicios.controller.catalog.BankCardController;
import com.arrebol.taxiservicios.controller.catalog.BankCardKardexController;
import com.arrebol.taxiservicios.model.catalog.BankCard;
import com.arrebol.taxiservicios.model.catalog.BankCardKardex;
import com.arrebol.taxiservicios.model.catalog.Color;
import com.arrebol.taxiservicios.model.enums.BankCardKardexType;
import com.arrebol.taxiservicios.model.enums.BasicType;
import com.arrebol.taxiservicios.services.catalog.BankCardService;
import com.arrebol.taxiservicios.services.catalog.ColorService;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.primefaces.event.ReorderEvent;
import org.primefaces.event.RowEditEvent;

/**
 *
 * @author oscarvargas
 */
@Named("bankCardKardexBean")
@ViewScoped
public class BankCardKardexBean extends TaxiGenericBean implements Serializable, Datatable {
    
    
     public void onBrandChange() {
        try {
            setBankCardKardex(getBankCardKardexCtrl().fillDatatableByBankCard(getSelectedBankCardId()));
            
        } catch (Exception e) {
            logger.error("onBrandChange", e);
            
            setBankCardKardex(new ArrayList<>());
            showMessage(FacesMessage.SEVERITY_ERROR, "Kardex", "Error al realizar la búsqueda del kardex por tarjeta bancaria");
        }
    }

    @Override
    public void editRow(RowEditEvent event) {
       
    }

    @Override
    public void onRowCancel(RowEditEvent event) {
     
    }

    @Override
    public void onRowReorder(ReorderEvent event) {
      
    }

    @Override
    public void addRow() {
      
    }

    @Override
    public void deleteRow() {
      
    }

    public List<BankCard> getBankCard() {
        return bankCard;
    }

    public void setBankCard(List<BankCard> bankCard) {
        this.bankCard = bankCard;
    }

    public List<BankCardKardex> getBankCardKardex() {
        return bankCardKardex;
    }

    public void setBankCardKardex(List<BankCardKardex> bankCardKardex) {
        this.bankCardKardex = bankCardKardex;
    }

    public BankCardController getBankCardCtrl() {
        return bankCardCtrl;
    }

    public void setBankCardCtrl(BankCardController bankCardCtrl) {
        this.bankCardCtrl = bankCardCtrl;
    }

    public BankCardKardexController getBankCardKardexCtrl() {
        return bankCardKardexCtrl;
    }

    public void setBankCardKardexCtrl(BankCardKardexController bankCardKardexCtrl) {
        this.bankCardKardexCtrl = bankCardKardexCtrl;
    }

    public String getSelectedBankCardId() {
        return selectedBankCardId;
    }

    public void setSelectedBankCardId(String selectedBankCardId) {
        this.selectedBankCardId = selectedBankCardId;
    }

    
    @PostConstruct
    public void init() {
        bankCardCtrl = new BankCardController();
        bankCardKardexCtrl = new BankCardKardexController();
        bankCard = bankCardCtrl.fillDatatable(getLoggedUser().getLocation());
        setBankCard(getBankCardCtrl().findAllBankCardsByLocation(getLoggedUser().getLocation().getId()));
    }

    private static final long serialVersionUID = -2400590341745672164L;
    final Logger logger = LogManager.getLogger(BankCardKardexBean.class);

    private List<BankCard> bankCard;
    private List<BankCardKardex> bankCardKardex;
    private String selectedBankCardId;

  
    private BankCardController bankCardCtrl;
    private BankCardKardexController bankCardKardexCtrl;

}
