package nc.bs.mmpac.pmo.pac0002.bp;

import nc.bs.mmpac.pmo.pac0002.pluginpoint.PMOPluginPoint;
import nc.bs.mmpac.pmo.pac0002.rule.PMOFilterBillStatusRule;
import nc.bs.mmpac.pmo.pac0002.rule.PMOPutAutoAuditPickmRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckDeptNotNullRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckPutCancelActApplyRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckPutCancelBatchBindRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckPutCancelDispatchNumRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckPutCancelHoldNumRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckPutCancelOperationRepRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOCheckPutCancelWrNumRule;
import nc.bs.mmpac.pmo.pac0002.rule.check.PMOPutCancelCheckPutPlanStatusRule;
import nc.bs.mmpac.pmo.pac0002.rule.fill.PMOFillBatchCodeRule;
import nc.bs.mmpac.pmo.pac0002.rule.fill.PMOFillPutValueRule;
import nc.bs.mmpac.pmo.pac0002.bp.rule.putBeforeCheckRule;
import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule;
import nc.impl.pubapp.pattern.rule.IFilterRule;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.util.mmf.framework.gc.GCUpdateBPTemplate;
import nc.vo.mmpac.pmo.pac0002.constant.PMOConstLang;
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
import nc.vo.mmpac.pmo.pac0002.enumeration.PMOFBillstatusEnum;

public class PMOPutBP {
	public PMOAggVO[] put(PMOAggVO[] fullBills, PMOAggVO[] originBills) {
		GCUpdateBPTemplate<PMOAggVO> bp = new GCUpdateBPTemplate<PMOAggVO>(PMOPluginPoint.PUT);

		addPutBeforeRule(bp.getAroundProcesser());

		addPutAfterRule(bp.getAroundProcesser());

		return (PMOAggVO[]) bp.update(fullBills, originBills);
	}

	private void addPutBeforeRule(CompareAroundProcesser<PMOAggVO> processer) {
		MMVOSagaFrozenValidateRule mMVOSagaFrozenValidateRule = new MMVOSagaFrozenValidateRule(true);
		processer.addBeforeRule(mMVOSagaFrozenValidateRule);

		IFilterRule<PMOAggVO> filterStatusRule = new PMOFilterBillStatusRule(PMOConstLang.getMSG_ACTION_NO_AUDIT(),
				PMOFBillstatusEnum.AUDIT);
		processer.addBeforeRule(filterStatusRule);

		IRule<PMOAggVO> checkDeptRule = new PMOCheckDeptNotNullRule();
		processer.addBeforeRule(checkDeptRule);

		IFilterRule<PMOAggVO> pickmRule = new PMOPutAutoAuditPickmRule();
		processer.addBeforeRule(pickmRule);

		IRule<PMOAggVO> fillValueRule = new PMOFillPutValueRule(false);
		processer.addBeforeRule(fillValueRule);

		IRule<PMOAggVO> batchcodeRule = new PMOFillBatchCodeRule();
		processer.addBeforeRule(batchcodeRule);
		IRule<PMOAggVO> putBeforeCheckRule = new putBeforeCheckRule();
		processer.addBeforeRule(putBeforeCheckRule);
	}

	private void addPutAfterRule(CompareAroundProcesser<PMOAggVO> processer) {
	}

	public PMOAggVO[] putCancel(PMOAggVO[] fullBills, PMOAggVO[] originBills) {
		GCUpdateBPTemplate<PMOAggVO> bp = new GCUpdateBPTemplate<PMOAggVO>(PMOPluginPoint.UNPUT);

		addPutCancelBeforeRule(bp.getAroundProcesser());

		addPutCancelAfterRule(bp.getAroundProcesser());

		return (PMOAggVO[]) bp.update(fullBills, originBills);
	}

	private void addPutCancelBeforeRule(CompareAroundProcesser<PMOAggVO> processer) {
		IFilterRule<PMOAggVO> filterStatusRule = new PMOFilterBillStatusRule(PMOConstLang.getMSG_ACTION_NO_AUDIT(),
				PMOFBillstatusEnum.AUDIT);
		processer.addBeforeRule(filterStatusRule);

		IRule<PMOAggVO> checkWRNumRule = new PMOCheckPutCancelWrNumRule();
		processer.addBeforeRule(checkWRNumRule);

		IRule<PMOAggVO> checkActApplyRule = new PMOCheckPutCancelActApplyRule();
		processer.addBeforeRule(checkActApplyRule);

		IRule<PMOAggVO> checkHoldNumRule = new PMOCheckPutCancelHoldNumRule();
		processer.addBeforeRule(checkHoldNumRule);

		IRule<PMOAggVO> checkBatchBindRule = new PMOCheckPutCancelBatchBindRule();
		processer.addBeforeRule(checkBatchBindRule);

		IRule<PMOAggVO> fillValueRule = new PMOFillPutValueRule(true);
		processer.addBeforeRule(fillValueRule);

		IRule<PMOAggVO> checkDispatchNumRule = new PMOCheckPutCancelDispatchNumRule();
		processer.addBeforeRule(checkDispatchNumRule);

		IRule<PMOAggVO> checkOperationRepRule = new PMOCheckPutCancelOperationRepRule();
		processer.addBeforeRule(checkOperationRepRule);

		IRule<PMOAggVO> putCancelCheckPutPlanStatusRule = new PMOPutCancelCheckPutPlanStatusRule();
		processer.addBeforeRule(putCancelCheckPutPlanStatusRule);
	}

	private void addPutCancelAfterRule(CompareAroundProcesser<PMOAggVO> processer) {
	}
}
