/*
 * 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.catalog;

import com.arrebol.apc.model.ModelParameter;
import com.arrebol.apc.model.core.Office;
import com.arrebol.apc.model.core.constance.LoanTypeCfg;
import com.arrebol.apc.model.loan.LoanType;
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 LoanTypeController implements Serializable{
    
    /**
     *
     * Searching all loans type.
     *
     * @param officeId
     * @return
     */
    public List<LoanType> fillLoanTypeDatatable(String officeId) {
        logger.debug("fillLoanTypeDatatable");
        List<ModelParameter> parameters = new ArrayList<>();

        parameters.add(new ModelParameter(LoanTypeCfg.FIELD_OFFICE, new Office(officeId)));

        return genericEntityRepository.xmlQueryAPCEntities(LoanType.class, LoanTypeCfg.QUERY_FIND_ALL_DATA_LOAN_TYPE_BY_OFFICE, parameters);
    }
    
    /**
     *
     * @param loanType
     * @return boolean
     */
    public boolean saveLoanType(LoanType loanType) {
        logger.debug("saveLoanTypeController");
        boolean success = genericEntityRepository.insertAPCEntity(loanType);

        return success;
    }
    
    /**
     *
     * @param loanType
     * @return boolean
     */
    public boolean updateByLoanTypeId(LoanType loanType) {
        logger.debug("updateByLoanTypeId");

        return genericEntityRepository.updateAPCEntity(loanType);
    }
    
    /**
     *
     * Searching loantype by id.
     *
     * @param loanTypeId
     * @return
     */
    public LoanType getLoanTypeById(String loanTypeId) {
        logger.debug("getLoanTypeById");

        return (LoanType) genericEntityRepository.selectAPCEntityById(LoanType.class, loanTypeId);
    }
    
    final Logger logger = LogManager.getLogger(LoanTypeController.class);
    private final GenericEntityRepository genericEntityRepository;

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