enum ELogicOperator
{
	OR = 0,
	AND = 1,
}

struct UIInteractionSkillCheck
{
	var isValid : Bool;
	var skillCheck : EDeviceChallengeSkill;
	var skillName : String;
	var requiredSkill : Int32;
	var playerSkill : Int32;
	var actionDisplayName : String;
	var hasAdditionalRequirements : Bool;
	var additionalReqOperator : ELogicOperator;
	var additionalRequirements : array< ConditionData >;
	var isPassed : Bool;
	var ownerID : EntityID;
}

struct ConditionData
{
	var conditionOperator : ELogicOperator;
	var requirementList : array< Condition >;
}

struct Condition
{
	var passed : Bool;
	var description : String;
}

struct ConditionGroupData
{
	const instanceeditable inlined var conditions : array< GameplayConditionBase >;
	instanceeditable var logicOperator : ELogicOperator;
}

class GameplayConditionContainer extends IScriptable
{
	protected instanceeditable var m_logicOperator : ELogicOperator;
	protected const instanceeditable inlined var m_conditionGroups : array< ConditionGroupData >;

	public function Evaluate( requester : GameObject ) : Bool
	{
		var passed : Bool;
		var i : Int32;
		if( m_logicOperator == ELogicOperator.AND )
		{
			passed = true;
		}
		for( i = 0; i < GetGroupsAmount(); i += 1 )
		{
			if( Evaluate( requester, m_conditionGroups[ i ] ) )
			{
				if( m_logicOperator == ELogicOperator.OR )
				{
					passed = true;
					break;
				}
			}
			else
			{
				if( m_logicOperator == ELogicOperator.AND )
				{
					passed = false;
					break;
				}
			}
		}
		return passed;
	}

	private function Evaluate( requester : GameObject, const group : ref< ConditionGroupData > ) : Bool
	{
		var passed : Bool;
		var i : Int32;
		if( group.logicOperator == ELogicOperator.AND )
		{
			passed = true;
		}
		for( i = 0; i < group.conditions.Size(); i += 1 )
		{
			if( group.conditions[ i ].Evaluate( requester ) )
			{
				if( group.logicOperator == ELogicOperator.OR )
				{
					passed = true;
					break;
				}
			}
			else
			{
				if( group.logicOperator == ELogicOperator.AND )
				{
					passed = false;
					break;
				}
			}
		}
		return passed;
	}

	public function CreateDescription( obj : GameObject, entID : EntityID ) : array< ConditionData >
	{
		var description : array< ConditionData >;
		var i : Int32;
		var k : Int32;
		var groupCondition : ConditionData;
		var conditionText : Condition;
		for( i = 0; i < GetGroupsAmount(); i += 1 )
		{
			groupCondition.conditionOperator = m_conditionGroups[ i ].logicOperator;
			groupCondition.requirementList.Clear();
			for( k = 0; k < m_conditionGroups[ i ].conditions.Size(); k += 1 )
			{
				m_conditionGroups[ i ].conditions[ k ].SetEntityID( entID );
				conditionText = m_conditionGroups[ i ].conditions[ k ].GetDescription( obj );
				groupCondition.requirementList.PushBack( conditionText );
			}
			description.PushBack( groupCondition );
		}
		return description;
	}

	public const function HasAdditionalRequirements() : Bool
	{
		if( GetGroupsAmount() > 0 )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	public const function GetOperator() : ELogicOperator
	{
		return m_logicOperator;
	}

	public const function GetGroupsAmount() : Int32
	{
		return m_conditionGroups.Size();
	}

}

