class DeviceOperationsContainer extends IScriptable
{
	private const instanceeditable inlined persistent var m_operations : array< DeviceOperationBase >;
	private const instanceeditable inlined var m_triggers : array< DeviceOperationsTrigger >;

	public function Initialize( owner : GameObject )
	{
		var i : Int32;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			m_triggers[ i ].Initialize( owner );
		}
	}

	public function UnInitialize( owner : GameObject )
	{
		var i : Int32;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			m_triggers[ i ].UnInitialize( owner );
		}
	}

	public function ToggleOperationByIndex( enable : Bool, index : Int32 )
	{
		m_operations[ index ].SetIsEnabled( enable );
	}

	public function ToggleOperationByName( enable : Bool, operationName : CName )
	{
		var i : Int32;
		for( i = 0; i < m_operations.Size(); i += 1 )
		{
			if( m_operations[ i ] == NULL )
			{
				continue;
			}
			if( m_operations[ i ].operationName == operationName )
			{
				m_operations[ i ].SetIsEnabled( enable );
			}
		}
	}

	public const function IsOperationEnabled( index : Int32 ) : Bool
	{
		return m_operations[ index ].IsEnabled();
	}

	public const function HasOperation( className : CName ) : Bool
	{
		var i : Int32;
		for( i = 0; i < m_operations.Size(); i += 1 )
		{
			if( m_operations[ i ].GetClassName() == className && m_operations[ i ].IsEnabled() )
			{
				return true;
			}
		}
		return false;
	}

	public const function IsOperationEnabled( operationName : CName ) : Bool
	{
		var i : Int32;
		for( i = 0; i < m_operations.Size(); i += 1 )
		{
			if( m_operations[ i ] == NULL )
			{
				continue;
			}
			if( m_operations[ i ].IsEnabled() )
			{
				return true;
			}
		}
		return false;
	}

	public function Execute( operationName : CName, owner : weak< GameObject > )
	{
		var i : Int32;
		for( i = 0; i < m_operations.Size(); i += 1 )
		{
			if( m_operations[ i ] == NULL )
			{
				continue;
			}
			if( m_operations[ i ].operationName == operationName && m_operations[ i ].IsEnabled() )
			{
				m_operations[ i ].Execute( owner );
				ToggleOperations( m_operations[ i ].toggleOperations );
			}
		}
	}

	public function Restore( operationName : CName, owner : weak< GameObject > )
	{
		var i : Int32;
		for( i = 0; i < m_operations.Size(); i += 1 )
		{
			if( m_operations[ i ] == NULL )
			{
				continue;
			}
			if( m_operations[ i ].operationName == operationName )
			{
				m_operations[ i ].Restore( owner );
			}
		}
	}

	private function ToggleOperations( const operations : ref< array< SToggleDeviceOperationData > > )
	{
		var i : Int32;
		for( i = 0; i < operations.Size(); i += 1 )
		{
			ToggleOperationByName( operations[ i ].enable, operations[ i ].operationName );
		}
	}

	public function EvaluateActivatorTriggers( owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : ActivatorOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( ActivatorOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( owner, this );
			}
		}
	}

	public function EvaluateFactTriggers( owner : weak< GameObject >, factName : CName )
	{
		var i : Int32;
		var trigger : FactOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( FactOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( owner, factName, this );
			}
		}
	}

	public function EvaluateFocusModeTriggers( owner : weak< GameObject >, operationType : ETriggerOperationType )
	{
		var i : Int32;
		var trigger : FocusModeOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( FocusModeOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( owner, operationType, this );
			}
		}
	}

	public function EvaluateSenseTriggers( owner : weak< GameObject >, activator : weak< GameObject >, operationType : ETriggerOperationType )
	{
		var i : Int32;
		var trigger : SensesOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( SensesOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( owner, activator, operationType, this );
			}
		}
	}

	public function EvaluateHitTriggers( owner : weak< GameObject >, activator : weak< GameObject >, attackData : AttackData )
	{
		var i : Int32;
		var trigger : HitOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( HitOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( owner, activator, attackData, this );
			}
		}
	}

	public function EvaluateInteractionAreaTriggers( areaTag : CName, owner : weak< GameObject >, activator : weak< GameObject >, operationType : gameinteractionsEInteractionEventType )
	{
		var i : Int32;
		var trigger : InteractionAreaOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( InteractionAreaOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( areaTag, owner, activator, operationType, this );
			}
		}
	}

	public function EvaluateTriggerVolumeTriggers( componentName : CName, owner : weak< GameObject >, activator : weak< GameObject >, operationType : ETriggerOperationType )
	{
		var i : Int32;
		var trigger : TriggerVolumeOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( TriggerVolumeOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( componentName, owner, activator, operationType, this );
			}
		}
	}

	public function EvaluateDeviceActionTriggers( actionClassName : CName, owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : DeviceActionOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( DeviceActionOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( actionClassName, owner, this );
			}
		}
	}

	public function RestoreDeviceActionOperations( actionClassName : CName, owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : DeviceActionOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( DeviceActionOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.RestoreOperation( actionClassName, owner, this );
			}
		}
	}

	public function EvaluateCustomActionTriggers( actionID : CName, owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : CustomActionOperationsTriggers;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( CustomActionOperationsTriggers )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( actionID, owner, this );
			}
		}
	}

	public function RestoreCustomActionOperations( actionID : CName, owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : CustomActionOperationsTriggers;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( CustomActionOperationsTriggers )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.RestoreOperation( actionID, owner, this );
			}
		}
	}

	public function EvaluateDoorStateTriggers( state : EDoorStatus, owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : DoorStateOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( DoorStateOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( state, owner, this );
			}
		}
	}

	public function EvaluateBaseStateTriggers( state : EDeviceStatus, owner : weak< GameObject > )
	{
		var i : Int32;
		var trigger : BaseStateOperationsTrigger;
		for( i = 0; i < m_triggers.Size(); i += 1 )
		{
			trigger = ( ( BaseStateOperationsTrigger )( m_triggers[ i ] ) );
			if( trigger != NULL )
			{
				trigger.EvaluateTrigger( state, owner, this );
			}
		}
	}

}

