/*<copyright                                                          */
/* notice="cics-rm-source-program"                                    */
/* pids="CA0U"                                                        */
/* years="2015"                                                       */
/* crc="1389280752" >                                                 */
/* 	Licensed Materials - Property of IBM                              */
/* 	"Restricted Materials of IBM"                                     */
/* 	CA0U                                                              */
/* 	(C) Copyright IBM Corp. 2015                                      */
/* 	US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */
/* </copyright>                                                       */
package com.ibm.cics.ucd.steps

import com.ibm.cics.core.model.CICSCore
import com.ibm.cics.core.model.FilteredContext
import com.ibm.cics.core.model.GenTypeClasses
import com.ibm.cics.core.model.ICPSM
import com.ibm.cics.core.model.LocalFileType
import com.ibm.cics.core.model.DataTableType
import com.ibm.cics.model.ICICSObject
import com.ibm.cics.model.ICICSType
import com.ibm.cics.sm.comm.ICICSAction
import com.ibm.cics.sm.comm.IContext
import com.ibm.cics.sm.comm.SystemManagerActions
import com.ibm.cics.ucd.CPSMHelper
import com.ibm.cics.ucd.properties.IntegerProperty
import com.ibm.cics.ucd.properties.ResourceNameListPropertySupportWildCard
import com.urbancode.air.AirPluginTool
import com.ibm.cics.ucd.exceptions.StepFailedException
import com.ibm.cics.ucd.msg.CICSUCDMessage

import java.text.MessageFormat
import java.util.Properties

class CloseResourceStep extends AbstractPerformActionStep {
// <copyright 
// notice="cics-rm-source-program" 
// pids="CA0U" 
// years="2015" 
// crc="3514276934" > 
// 	Licensed Materials - Property of IBM 
// 	"Restricted Materials of IBM" 
// 	CA0U 
// 	(C) Copyright IBM Corp. 2015 
// 	US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
// </copyright> 
	public static final noWaitCloseType = [LocalFileType.getInstance().getResourceTableName(), DataTableType.getInstance().getResourceTableName()]
		
	public CloseResourceStep(String inputPropertyFile, String outputPropertyFile) {
		this(inputPropertyFile, outputPropertyFile, CICSCore.getCPSM())
	}

	public CloseResourceStep(AirPluginTool apTool) {
		this(apTool, CICSCore.getCPSM())
	}

	/**
	 * Primarily to support unit testing
	 */
	CloseResourceStep(String inputPropertyFile, String outputPropertyFile, ICPSM cpsm) {
		super(inputPropertyFile, outputPropertyFile)
		this.cpsm = cpsm
	}

	CloseResourceStep(AirPluginTool apTool, ICPSM cpsm) {
		super(apTool)
		this.cpsm = cpsm
	}
	
	@Override
	protected ICICSAction getCicsAction(Properties props) {
		//For 'File' and 'Data Table' resource, the Close action is set BUSY(NoWait) as default
		if (noWaitCloseType.contains(props[RESOURCE_TYPE])){
			return SystemManagerActions.CloseNoWait
		}		
		return SystemManagerActions.Close
	}

}
