//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.bs.mmpsc.pscsettle.bp;

import nc.bs.mmpsc.pscsettle.plugin.SettlePluginPoint;
import nc.bs.mmpsc.pscsettle.rule.SettleStatusCheckRule;
import nc.bs.mmpsc.pscsettle.rule.SettleStatusUpdateRule;
import nc.bs.mmpsc.pscsettle.rule.approve.FillAuditInfoRule;
import nc.bs.mmpsc.pscsettle.rule.unapprove.FilterAdjustedRule;
import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule;
import nc.bs.mmpub.rule.MMVOToAPRule;
import nc.impl.pubapp.pattern.data.bill.template.UpdateBPTemplate;
import nc.impl.pubapp.pattern.rule.IFilterRule;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.mmpsc.pscsettle.entity.AggSettleVO;
import nc.vo.mmpsc.pscsettle.enumeration.SettleStatusEnum;

public class SettleApproveBP {
    public SettleApproveBP() {
    }

    public AggSettleVO[] approve(AggSettleVO[] clientBills, AggSettleVO[] originBills) {
        UpdateBPTemplate<AggSettleVO> bp = new UpdateBPTemplate(SettlePluginPoint.APPROVE);
        this.addBeforeRule(bp.getAroundProcesser());
        this.addAfterRule(bp.getAroundProcesser(), originBills);
        return (AggSettleVO[])bp.update(clientBills, originBills);
    }

    private void addAfterRule(CompareAroundProcesser<AggSettleVO> processer, AggSettleVO[] originBills) {

        IRule<AggSettleVO> var5 = new MMVOToAPRule(originBills);
        processer.addAfterRule(var5);
    }

    private void addBeforeRule(CompareAroundProcesser<AggSettleVO> processer) {
        IRule<AggSettleVO> checkFrozenRule = new MMVOSagaFrozenValidateRule(true);
        processer.addBeforeRule(checkFrozenRule);
        IRule<AggSettleVO> crule = new SettleStatusCheckRule(SettleStatusEnum.FREE);
        processer.addBeforeRule(crule);
        IFilterRule<AggSettleVO> filterRule = new FilterAdjustedRule();
        processer.addBeforeRule(filterRule);
        IRule<AggSettleVO> rule = new SettleStatusUpdateRule(SettleStatusEnum.APPROVED);
        processer.addBeforeRule(rule);
        IRule<AggSettleVO> auditRule = new FillAuditInfoRule();
        processer.addBeforeRule(auditRule);
    }
}
