/*
 * 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.apc.web.beans.admin;

import com.arrebol.apc.controller.GenericController;
import com.arrebol.apc.controller.admin.StatsSummaryController;
import com.arrebol.apc.model.views.StatsSummaryView;
import com.arrebol.apc.web.beans.Datatable;
import com.arrebol.apc.web.beans.GenericBean;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.ReorderEvent;
import org.primefaces.event.RowEditEvent;

/**
 *
 * @author David Rodriguez
 */
@Named("statsSummaryManager")
@ViewScoped
public class StatsSummaryBean extends GenericBean implements Serializable, Datatable {

    public void searchHistoricalAction() {
        try {
            if (getStarDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR, getBundlePropertyFile().getString("generic.start.date"), getBundlePropertyFile().getString("generic.end.date.error"));
            } else {
                setSummary(fillDatatableSummary());
                setTotalSummary(fillTotalSummary());
            }
        } catch (Exception e) {
        }
    }

    public BigDecimal searchTotalSummaryAction() {
        try {
            if (getStarDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR, getBundlePropertyFile().getString("generic.start.date"), getBundlePropertyFile().getString("generic.end.date.error"));
            } else {
                setTotalSummary(fillTotalSummary());
            }
        } catch (Exception e) {
        }
        return getTotalSummary();
    }

    public StatsSummaryController getSummaryCtrl() {
        return summaryCtrl;
    }

    public void setSummaryCtrl(StatsSummaryController summaryCtrl) {
        this.summaryCtrl = summaryCtrl;
    }

    public GenericController getGenericCtrl() {
        return genericCtrl;
    }

    public void setGenericCtrl(GenericController genericCtrl) {
        this.genericCtrl = genericCtrl;
    }

    public List<StatsSummaryView> fillDatatableSummary() {
        return getSummaryCtrl().fillSummaryDataTable(getStarDate(), getEndDate());
    }

    public BigDecimal fillTotalSummary() {
        return getSummaryCtrl().fillTotalSummary(getStarDate(), getEndDate());
    }

    public List<StatsSummaryView> getSummary() {
        return summary;
    }

    public void setSummary(List<StatsSummaryView> summary) {
        this.summary = summary;
    }

    public StatsSummaryView getSelectedSummary() {
        return selectedSummary;
    }

    public void setSelectedSummary(StatsSummaryView selectedSummary) {
        this.selectedSummary = selectedSummary;
    }

    public BigDecimal getTotalSummary() {
        return totalSummary;
    }

    public void setTotalSummary(BigDecimal totalSummary) {
        this.totalSummary = totalSummary;
    }

    private StatsSummaryController summaryCtrl;
    private GenericController genericCtrl;
    private List<StatsSummaryView> summary;
    private StatsSummaryView selectedSummary;
    private BigDecimal totalSummary;

    @PostConstruct
    public void init() {
        loadBundlePropertyFile();
        initStartAndEndDates(Calendar.DAY_OF_WEEK, 2);

        summaryCtrl = new StatsSummaryController();
        genericCtrl = new GenericController();
        summary = fillDatatableSummary();
        totalSummary = fillTotalSummary();
    }

    @Override
    public void editRow(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowCancel(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowReorder(ReorderEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void addRow() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteRow() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
