package nc.bs.mmpac.pickm.bp;


import nc.bs.mmpac.pickm.bp.rule.AfterApproveRuleSyncRZWMS;
import nc.bs.mmpac.pickm.plugin.PickmPluginPoint;
import nc.bs.mmpac.pickm.rule.PickmApproveCheckStatusRule;
import nc.bs.mmpac.pickm.rule.PickmCheckAuditRule;
import nc.bs.mmpac.pickm.rule.PickmFbackflustimeCheckRule;
import nc.bs.mmpac.pickm.rule.PickmSetStatusRule;
import nc.bs.mmpub.rule.MMATOMaterialCheckRule;
import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule;
import nc.impl.pubapp.pattern.data.bill.template.UpdateBPTemplate;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
import nc.impl.pubapp.pattern.rule.ICompareRule;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.mmpac.pickm.entity.AggPickmVO;
import nc.vo.mmpac.pickm.enumeration.FbillstatusEnum;

public class PickmApproveBP {

    private void addAfterRule(CompareAroundProcesser<AggPickmVO> processer) {
        //备料计划审批推送锐制
        IRule<AggPickmVO> pickmstatusFilterRule = new AfterApproveRuleSyncRZWMS();
        processer.addAfterRule(pickmstatusFilterRule);
    }

    private void addBeforeRule(CompareAroundProcesser<AggPickmVO> processer) {
        ICompareRule<AggPickmVO> pickmstatusFilterRule = new PickmApproveCheckStatusRule(true);
        processer.addBeforeRule(pickmstatusFilterRule);
        IRule<AggPickmVO> sagasCheckrule = new MMVOSagaFrozenValidateRule(true);
        processer.addBeforeRule(sagasCheckrule);
        IRule<AggPickmVO> pickmAuditCheckRule = new PickmCheckAuditRule();
        processer.addBeforeRule(pickmAuditCheckRule);
        IRule<AggPickmVO> mmatoMaterialCheckRule = new MMATOMaterialCheckRule("cmaterialvid", (String) null, "cffileid");
        processer.addBeforeRule(mmatoMaterialCheckRule);
        IRule<AggPickmVO> checkFbackFlusTime = new PickmFbackflustimeCheckRule();
        processer.addBeforeRule(checkFbackFlusTime);
        IRule<AggPickmVO> pickmSetStatusRule = new PickmSetStatusRule(FbillstatusEnum.AUDIT_STATE);
        processer.addBeforeRule(pickmSetStatusRule);
    }

    public AggPickmVO[] batchApprovePickm(AggPickmVO[] vos) {
        if (MMValueCheck.isEmpty(vos)) {
            return null;
        } else {
            UpdateBPTemplate<AggPickmVO> bpTemplate = new UpdateBPTemplate(PickmPluginPoint.APPROVE);
            BillTransferTool<AggPickmVO> transTool = new BillTransferTool(vos);
            this.addBeforeRule(bpTemplate.getAroundProcesser());
            this.addAfterRule(bpTemplate.getAroundProcesser());
            AggPickmVO[] fullBills = (AggPickmVO[]) transTool.getClientFullInfoBill();
            AggPickmVO[] originBills = (AggPickmVO[]) transTool.getOriginBills();
            AggPickmVO[] retBills = (AggPickmVO[]) bpTemplate.update(fullBills, originBills);
            return retBills;
        }
    }

}
