package com.cim.idm.mwmsextend.checkplan.management.action;

import java.util.HashMap;

import com.cim.idm.framework.action.info.ValidationFormat;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.data.TransitionInfo;
import com.cim.idm.framework.exception.ext.DuplicateNameSignal;
import com.cim.idm.framework.exception.ext.FrameworkErrorSignal;
import com.cim.idm.framework.orm.info.DataInfo;
import com.cim.idm.mwmsextend.checkplan.CheckPlanServiceProxy;
import com.cim.idm.mwmsextend.checkplan.management.CheckPlanService;
import com.cim.idm.mwmsextend.checkplan.management.data.CheckPlan;
import com.cim.idm.mwmsextend.checkplan.management.data.CheckPlanKey;
import com.cim.idm.wmspackage.action.CommonAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component("CheckPlanRemoveAction")
public class RemoveAction extends CommonAction{
	@Autowired
	@Qualifier("checkPlanService")
	private CheckPlanService checkPlanService;

	public void remove(DataInfo oldCheckPlanData,
			DataInfo newCheckPlanData, EventInfo eventInfo,
			TransitionInfo transitionInfo,
			HashMap<String, ValidationFormat> validationList)
			throws DuplicateNameSignal, FrameworkErrorSignal {
		CheckPlan checkPlan = (CheckPlan) newCheckPlanData;
		CheckPlanKey key = checkPlan.getKey();
		CheckPlanServiceProxy.getCheckPlanService().delete(key);
	}

	public void remove(DataInfo[] oldCheckPlanDataArray, DataInfo[] newCheckPlanDataArray,
			EventInfo eventInfo, TransitionInfo[] transitionInfoArray,
			HashMap<String, ValidationFormat> validationList)
			throws DuplicateNameSignal, FrameworkErrorSignal{
		    CheckPlan[] checkPlanArray = new CheckPlan[newCheckPlanDataArray.length];
		    System.arraycopy(newCheckPlanDataArray,0,checkPlanArray,0,newCheckPlanDataArray.length);
		    CheckPlanKey[] keyArray = new CheckPlanKey[newCheckPlanDataArray.length];
		    for(int i=0;i<newCheckPlanDataArray.length;i++)
		    {
		    	keyArray[i]=checkPlanArray[i].getKey();
		    }
		    CheckPlanServiceProxy.getCheckPlanService().delete(keyArray);
	}
}
