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

package nc.bs.so.m32.maintain;

import nc.bs.scmpub.rule.VOSagaFrozenValidateRule;
import nc.bs.scmpub.ssc.rule.BaseBillDeleteSyncImage;
import nc.bs.scmpub.ssc.rule.SyncRPBillRuleForDelete;
import nc.bs.so.m32.maintain.rule.delete.*;
import nc.bs.so.m32.plugin.BP32PlugInPoint;
import nc.impl.pubapp.pattern.data.bill.BillDelete;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pubapp.pattern.log.TimeLog;
import nc.vo.scmpub.res.billtype.SOBillType;
import nc.vo.so.m32.entity.SaleInvoiceVO;

public class DeleteSaleInvoiceBP {
    public DeleteSaleInvoiceBP() {
    }

    public void delete(SaleInvoiceVO[] bills) {
        AroundProcesser<SaleInvoiceVO> processer = new AroundProcesser(BP32PlugInPoint.DeleteAction);
        this.addBeforeRule(processer);
        this.addAfterRule(processer);
        TimeLog.logStart();
        processer.before(bills);
        TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006008_0", "04006008-0020"));
        TimeLog.logStart();
        BillDelete<SaleInvoiceVO> bo = new BillDelete();
        bo.delete(bills);
        TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006008_0", "04006008-0021"));
        TimeLog.logStart();
        processer.after(bills);
        TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006008_0", "04006008-0022"));
    }

    private void addAfterRule(AroundProcesser<SaleInvoiceVO> processer) {
        IRule<SaleInvoiceVO> rule = new ReturnBillCodeRule();
        processer.addAfterRule(rule);
        IRule<SaleInvoiceVO> updateOppDeleteRule = new UpdateOppDeleteRule();
        processer.addAfterRule(updateOppDeleteRule);
        IRule<SaleInvoiceVO> rewriteARSubDeleteRule = new RewriteARSubDeleteRule();
        processer.addAfterRule(rewriteARSubDeleteRule);
        IRule<SaleInvoiceVO> rewriteBillDeleteRule = new RewriteBillDeleteRule();
        processer.addAfterRule(rewriteBillDeleteRule);
        IRule<SaleInvoiceVO> baseBillDeleteSyncImage = new BaseBillDeleteSyncImage();
        processer.addAfterRule(baseBillDeleteSyncImage);
        IRule<SaleInvoiceVO> syncRPBillRuleForDelete = new SyncRPBillRuleForDelete(SOBillType.Invoice.getCode());
        processer.addAfterRule(syncRPBillRuleForDelete);
        // 删除后同步修改BIP的开票申请存的NCC信息
        IRule<SaleInvoiceVO> syncBipBillRuleForDelete = new SyncBipBillRuleForDelete();
        processer.addAfterRule(syncBipBillRuleForDelete);
    }

    private void addBeforeRule(AroundProcesser<SaleInvoiceVO> processer) {
        IRule<SaleInvoiceVO> rule = new VOSagaFrozenValidateRule(true);
        processer.addBeforeRule(rule);
        IRule<SaleInvoiceVO> checkEnableDeleteRule = new CheckEnableDeleteRule();
        processer.addBeforeRule(checkEnableDeleteRule);
    }
}
