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

import com.arrebol.apc.model.ModelParameter;
import com.arrebol.apc.model.catalog.People;
import com.arrebol.apc.model.catalog.constance.PeopleCfg;
import com.arrebol.apc.model.core.constance.LoanCfg;
import com.arrebol.apc.model.enums.ActiveStatus;
import com.arrebol.apc.model.loan.Loan;
import com.arrebol.apc.repository.GenericEntityRepository;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Oscar Armando Vargas Cardenas <oscar.vargas@arrebol.com.mx>
 */
public class EndorsementController extends PeopleController implements Serializable{
    
    /**
     *
     * Searching all endorsement.
     *
     * @param officeId
     * @return
     */
    public List<People> fillEndorsementsDatatable(String officeId) {
        logger.debug("fillEndorsementsDatatable");
        List<ModelParameter> parameters = new ArrayList<>();

        parameters.add(new ModelParameter(PeopleCfg.FIELD_ACTIVE_STATUS, ActiveStatus.ENEBLED));

        return genericEntityRepository.xmlQueryAPCEntities(People.class, PeopleCfg.QUERY_FIND_ALL_ENDORSEMENT, parameters);
    }
    
    /**
     *
     * Searching all loan by endorsement.
     *
     * @param peopleId
     * @return
     */
    public List<Loan> findLoanByEndorsement(String peopleId) {
        logger.debug("findLoanByEndorsement");
        List<ModelParameter> parameters = new ArrayList<>();

        parameters.add(new ModelParameter(LoanCfg.FIELD_ENDORSEMENT, new People(peopleId)));

        return genericEntityRepository.xmlQueryAPCEntities(Loan.class, LoanCfg.QUERY_FIND_LOAN_BY_ENDORSEMENT, parameters);
    }
    
    final Logger logger = LogManager.getLogger(EndorsementController.class);
    private final GenericEntityRepository genericEntityRepository;

    public EndorsementController() {
        this.genericEntityRepository = new GenericEntityRepository();
    }
}
