enum EVarDBMode
{
	Add = 0,
	Set = 1,
	Invalid = 2,
}

struct SDebugChoice
{
	instanceeditable var choiceName : CName;
	instanceeditable var factValue : Int32;
	instanceeditable var factmode : EVarDBMode;
}

class DebugInteractionObject extends GameObject
{
	private const instanceeditable var m_choices : array< SDebugChoice >;
	private var m_interaction : InteractionComponent;

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'interaction', 'InteractionComponent', true );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_interaction = ( ( InteractionComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'interaction' ) ) );
	}

	protected event OnGameAttached()
	{
		InitializeChoices();
	}

	protected event OnInteractionChoice( choiceEvent : InteractionChoiceEvent )
	{
		ResolveFact( choiceEvent.choice.caption );
	}

	private function InitializeChoices()
	{
		var i : Int32;
		var choicesArr : array< InteractionChoice >;
		for( i = 0; i < m_choices.Size(); i += 1 )
		{
			if( m_choices[ i ].choiceName == '' )
			{
				continue;
			}
			choicesArr.PushBack( CreateChoice( NameToString( m_choices[ i ].choiceName ), m_choices[ i ].factValue ) );
		}
		m_interaction.SetChoices( choicesArr );
	}

	private function CreateChoice( const choiceName : ref< String >, data : Int32 ) : InteractionChoice
	{
		var choice : InteractionChoice;
		choice.choiceMetaData.tweakDBName = choiceName;
		choice.caption = choice.choiceMetaData.tweakDBName;
		choice.data.PushBack( data );
		return choice;
	}

	private function ResolveFact( const factName : ref< String > )
	{
		var i : Int32;
		for( i = 0; i < m_choices.Size(); i += 1 )
		{
			if( factName == "" )
			{
				continue;
			}
			if( factName == NameToString( m_choices[ i ].choiceName ) )
			{
				if( m_choices[ i ].factmode == EVarDBMode.Add )
				{
					AddFact( GetGame(), m_choices[ i ].choiceName, m_choices[ i ].factValue );
				}
				else if( m_choices[ i ].factmode == EVarDBMode.Set )
				{
					SetFactValue( GetGame(), m_choices[ i ].choiceName, m_choices[ i ].factValue );
				}
			}
		}
	}

}

