class InvisibleSceneStash extends Device
{
	default m_controllerTypeName = 'InvisibleSceneStashController';

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		super.OnTakeControl( ri );
		m_controller = ( ( InvisibleSceneStashController )( EntityResolveComponentsInterface.GetComponent( ri, 'controller' ) ) );
	}

	protected event OnQuestUndressPlayer( evt : UndressPlayer )
	{
		var player : PlayerPuppet;
		var equipmentSys : EquipmentSystem;
		var equipmentData : EquipmentSystemPlayerData;
		var slotList : array< gamedataEquipmentArea >;
		var unequipSetRequest : QuestDisableWardrobeSetRequest;
		var itemList : array< ItemID >;
		var id : ItemID;
		var i : Int32;
		player = GetPlayer( GetGame() );
		equipmentSys = GetEquipmentSystem();
		equipmentData = EquipmentSystem.GetData( player );
		slotList = GetSlots( equipmentData.IsBuildCensored() || evt.isCensored );
		unequipSetRequest = new QuestDisableWardrobeSetRequest;
		unequipSetRequest.owner = player;
		equipmentSys.QueueRequest( unequipSetRequest );
		for( i = 0; i < slotList.Size(); i += 1 )
		{
			id = equipmentData.GetActiveItem( slotList[ i ] );
			if( ItemID.IsValid( id ) )
			{
				itemList.PushBack( id );
				equipmentSys.QueueRequest( CreateUnequipRequest( player, slotList[ i ] ) );
			}
		}
		GetDevicePS().StoreItems( itemList );
	}

	protected event OnQuestDressPlayer( evt : DressPlayer )
	{
		var equipSetRequest : QuestRestoreWardrobeSetRequest;
		var itemList : array< ItemID >;
		var player : PlayerPuppet;
		var equipmentSys : EquipmentSystem;
		var i : Int32;
		equipSetRequest = new QuestRestoreWardrobeSetRequest;
		itemList = GetDevicePS().GetItems();
		player = GetPlayer( GetGame() );
		equipmentSys = GetEquipmentSystem();
		equipSetRequest.owner = player;
		equipmentSys.QueueRequest( equipSetRequest );
		for( i = 0; i < itemList.Size(); i += 1 )
		{
			equipmentSys.QueueRequest( CreateEquipRequest( player, itemList[ i ] ) );
		}
		GetDevicePS().ClearStoredItems();
	}

	private const function GetSlots( censored : Bool ) : array< gamedataEquipmentArea >
	{
		var slots : array< gamedataEquipmentArea >;
		slots.PushBack( gamedataEquipmentArea.Face );
		slots.PushBack( gamedataEquipmentArea.Head );
		slots.PushBack( gamedataEquipmentArea.Feet );
		slots.PushBack( gamedataEquipmentArea.Legs );
		slots.PushBack( gamedataEquipmentArea.InnerChest );
		slots.PushBack( gamedataEquipmentArea.OuterChest );
		slots.PushBack( gamedataEquipmentArea.Outfit );
		if( !( censored ) )
		{
			slots.PushBack( gamedataEquipmentArea.UnderwearBottom );
			slots.PushBack( gamedataEquipmentArea.UnderwearTop );
		}
		return slots;
	}

	private const function GetEquipmentSystem() : EquipmentSystem
	{
		return ( ( EquipmentSystem )( GameInstance.GetScriptableSystemsContainer( GetGame() ).Get( 'EquipmentSystem' ) ) );
	}

	private const function CreateUnequipRequest( player : PlayerPuppet, area : gamedataEquipmentArea ) : UnequipRequest
	{
		var unequipRequest : UnequipRequest;
		unequipRequest = new UnequipRequest;
		unequipRequest.owner = player;
		unequipRequest.slotIndex = 0;
		unequipRequest.areaType = area;
		return unequipRequest;
	}

	private const function CreateEquipRequest( player : PlayerPuppet, item : ItemID ) : EquipRequest
	{
		var equipRequest : EquipRequest;
		equipRequest = new EquipRequest;
		equipRequest.owner = player;
		equipRequest.slotIndex = 0;
		equipRequest.itemID = item;
		return equipRequest;
	}

	private const override function GetController() : InvisibleSceneStashController
	{
		return ( ( InvisibleSceneStashController )( m_controller ) );
	}

	public const override function GetDevicePS() : InvisibleSceneStashControllerPS
	{
		return GetController().GetPS();
	}

}

class UndressPlayer extends Event
{
	editable var isCensored : Bool;

	public constexpr function GetFriendlyDescription() : String
	{
		return "Undress Player";
	}

}

class DressPlayer extends Event
{

	public constexpr function GetFriendlyDescription() : String
	{
		return "Dress Player Up";
	}

}

