/*
 * 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.controller.lazy.services;

import com.arrebol.taxiservicios.controller.util.FilterMap;
import com.arrebol.taxiservicios.controller.util.LazyDataModelDAORepository;
import com.arrebol.taxiservicios.model.dashboard.FeeDashboardPersonListView;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.enterprise.context.RequestScoped;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.primefaces.model.SortOrder;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@RequestScoped
public class FeeDashboardPersonListViewLazyServiceImpl extends LazyDataModelDAORepository<FeeDashboardPersonListView> implements FeeDashboardPersonListViewLazyService {

    @Override
    public long countPaginator(Map<String, Object> filterBy) {
        logger.debug("countPaginator");
        try {
            StringBuilder sqlQuery = new StringBuilder("SELECT COUNT(id) FROM FeeDashboardPersonListView ");

            sqlQuery.append(FilterMap.genericFilterByMapping(filterBy, false));

            return lazyLoadingEntityCount(sqlQuery.toString(), null);
        } catch (Exception e) {
            logger.error("countPaginator", e);

            return 0l;
        }
    }

    @Override
    public List<FeeDashboardPersonListView> lazyEntityListPaginator(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filterBy) {
        logger.debug("fillListPaginator");
        try {
            StringBuilder sqlQuery = new StringBuilder("FROM FeeDashboardPersonListView ");

            sqlQuery.append(FilterMap.genericFilterByMapping(filterBy, false));
            sqlQuery.append(" ORDER BY ");

            if (null == sortField || "".equals(sortField)) {
                sqlQuery.append(" total DESC");
            } else {
                sqlQuery.append(sortField);

                if (null != sortOrder) {
                    sqlQuery.append(" ");
                    sqlQuery.append(sortOrder.equals(SortOrder.ASCENDING) ? "ASC" : "DESC");
                } else {
                    sqlQuery.append(" DESC");
                }
            }

            return lazyLoadingEntityList(FeeDashboardPersonListView.class, sqlQuery.toString(), null, first, pageSize);
        } catch (Exception e) {
            logger.error("lazyEntityListPaginator", e);
            return new ArrayList();
        }
    }

    final Logger logger = LogManager.getLogger(getClass());

    @Override
    public List<FeeDashboardPersonListView> lazyEntityListPaginator(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filterBy, String idlocation) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public long countPaginator(Map<String, Object> filterBy, String idLocation) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}
