package com.fp.general.rules.query;

import java.util.List;

import com.fp.base.persistence.util.helper.GeneralDescriptions;
import com.fp.bpm.query.Query;
import com.fp.dto.Response;
import com.fp.dto.query.QueryRequest;
import com.fp.dto.rules.QueryRule;
import com.fp.persistence.pgeneral.transf.TgeneMaturation;

/**
 * Clase que se encarga de completar la descripcion de los items de la tabla TgeneMaturation
 * 
 * @author scastillo
 * @version 2.1
 */
public class CompleteMaturation extends QueryRule {

    /**
     * Método que completa las descripciones de la tabla TgeneMaturation
     * 
     * @param pQueryRequest
     * @return
     * @throws Exception
     */
    @Override
    public QueryRequest process(QueryRequest pQueryRequest) throws Exception {
        Response response = pQueryRequest.getResponse();
        Query qry = new Query();
        qry.process(pQueryRequest);
        List<Object> lobjects = (List<Object>) response.get("TGENEMATURATION");
        if (lobjects == null) {
            return pQueryRequest;
        }
        for (Object obj : lobjects) {
            TgeneMaturation tgeneMaturation = (TgeneMaturation) obj;
            if ((tgeneMaturation.getTransactionmodule() != null) && (tgeneMaturation.getTransactioncode() != null)
                    && (tgeneMaturation.getTransactionversion() != null)) {
                if (tgeneMaturation.getDebititem() != null) {
                    tgeneMaturation.addAddtionalInfo("debititemdesc", GeneralDescriptions.getTransactionItemdesc(
                            tgeneMaturation.getTransactionmodule(), tgeneMaturation.getTransactioncode(), tgeneMaturation.getTransactionversion(),
                            tgeneMaturation.getDebititem()));
                } else {
                    tgeneMaturation.addAddtionalInfo("debititemdesc", null);
                }
                if (tgeneMaturation.getCredititem() != null) {
                    tgeneMaturation.addAddtionalInfo("credititemdesc", GeneralDescriptions.getTransactionItemdesc(
                            tgeneMaturation.getTransactionmodule(), tgeneMaturation.getTransactioncode(), tgeneMaturation.getTransactionversion(),
                            tgeneMaturation.getCredititem()));
                } else {
                    tgeneMaturation.addAddtionalInfo("credititemdesc", null);
                }
            } else {
                tgeneMaturation.addAddtionalInfo("debititemdesc", null);
                tgeneMaturation.addAddtionalInfo("credititemdesc", null);
            }
        }
        return pQueryRequest;
    }
}
