class CraftItemForTarget extends ActionBool
{
	var itemID : TweakDBID;

	public function SetProperties()
	{
		actionName = 'CraftItem';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'Craft Item', true, 'LocKey#17846', 'LocKey#17846' );
	}

	public constexpr static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		return true;
	}

	public function CreateActionWidgetPackage( const displayText : ref< String >, const additionalText : ref< String >, imageAtlasImageID : CName, optional actions : array< DeviceAction > )
	{
		m_actionWidgetPackage.wasInitalized = true;
		m_actionWidgetPackage.dependendActions = actions;
		m_actionWidgetPackage.libraryPath = GetInkWidgetLibraryPath();
		m_actionWidgetPackage.libraryID = GetInkWidgetLibraryID();
		m_actionWidgetPackage.widgetName = displayText;
		m_actionWidgetPackage.displayName = ( displayText + ":" ) + additionalText;
		m_actionWidgetPackage.widgetTweakDBID = GetInkWidgetTweakDBID();
		ResolveActionWidgetTweakDBData();
	}

	public override function GetInkWidgetLibraryID() : CName
	{
		return '';
	}

	public override function GetInkWidgetTweakDBID() : TweakDBID
	{
		return T"DevicesUIDefinitions.VendorItemActionWidget";
	}

}

class BuyItemFromVendor extends ActionBool
{
	var itemID : ItemID;

	public function SetProperties()
	{
		actionName = 'BuyItem';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'Buy Item', true, 'LocKey#17847', 'LocKey#17847' );
	}

	public constexpr static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		return true;
	}

	public function CreateActionWidgetPackage( const displayText : ref< String >, const additionalText : ref< String >, imageAtlasImageID : CName, optional actions : array< DeviceAction > )
	{
		m_actionWidgetPackage.wasInitalized = true;
		m_actionWidgetPackage.dependendActions = actions;
		m_actionWidgetPackage.libraryPath = GetInkWidgetLibraryPath();
		m_actionWidgetPackage.libraryID = GetInkWidgetLibraryID();
		m_actionWidgetPackage.widgetName = displayText;
		m_actionWidgetPackage.displayName = ( displayText + ":" ) + additionalText;
		m_actionWidgetPackage.widgetTweakDBID = GetInkWidgetTweakDBID();
		ResolveActionWidgetTweakDBData();
	}

	public override function GetInkWidgetLibraryID() : CName
	{
		return '';
	}

	public override function GetInkWidgetTweakDBID() : TweakDBID
	{
		return T"DevicesUIDefinitions.VendorItemActionWidget";
	}

}

class SellItemToVendor extends ActionBool
{
	var itemID : ItemID;

	public function SetProperties()
	{
		actionName = 'SellItem';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'Sell Item', true, 'LocKey#17848', 'LocKey#17848' );
	}

	public constexpr static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		return true;
	}

	public function CreateActionWidgetPackage( const displayText : ref< String >, const additionalText : ref< String >, imageAtlasImageID : CName, optional actions : array< DeviceAction > )
	{
		m_actionWidgetPackage.wasInitalized = true;
		m_actionWidgetPackage.dependendActions = actions;
		m_actionWidgetPackage.libraryPath = GetInkWidgetLibraryPath();
		m_actionWidgetPackage.libraryID = GetInkWidgetLibraryID();
		m_actionWidgetPackage.widgetName = displayText;
		m_actionWidgetPackage.displayName = ( displayText + ":" ) + additionalText;
		m_actionWidgetPackage.widgetTweakDBID = GetInkWidgetTweakDBID();
		ResolveActionWidgetTweakDBData();
	}

	public override function GetInkWidgetLibraryID() : CName
	{
		return '';
	}

	public override function GetInkWidgetTweakDBID() : TweakDBID
	{
		return T"DevicesUIDefinitions.VendorItemActionWidget";
	}

}

class DispenceItemFromVendor extends ActionBool
{
	private var m_itemID : ItemID;
	private var m_price : Int32;
	default m_price = -1;
	private var m_atlasTexture : CName;

	public function SetProperties( iteID : ItemID, optional price : Int32, optional texture : CName )
	{
		actionName = 'DispenceItem';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'Dispence Item', true, 'LocKey#17849', 'LocKey#17849' );
		m_itemID = iteID;
		m_price = price;
		m_atlasTexture = texture;
	}

	public static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		if( IsAvailable( device ) )
		{
			return true;
		}
		return false;
	}

	public static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		if( device.IsON() )
		{
			return true;
		}
		return false;
	}

	public function CanPay( optional user : GameObject ) : Bool
	{
		var userMoney : Int32;
		var transactionSys : TransactionSystem;
		var price : Int32;
		if( !( user ) )
		{
			user = GetExecutor();
		}
		if( !( user ) )
		{
			return false;
		}
		transactionSys = GameInstance.GetTransactionSystem( user.GetGame() );
		userMoney = transactionSys.GetItemQuantity( user, MarketSystem.Money() );
		price = m_price;
		if( price == -1 )
		{
			price = MarketSystem.GetBuyPrice( user.GetGame(), PersistentID.ExtractEntityID( GetPersistentID() ), m_itemID );
		}
		return userMoney > price;
	}

	public const function GetItemID() : ItemID
	{
		return m_itemID;
	}

	public const function GetPrice() : Int32
	{
		return m_price;
	}

	public const function GetAtlasTexture() : CName
	{
		return m_atlasTexture;
	}

	public override function CreateActionWidgetPackage( optional actions : array< DeviceAction > )
	{
		var widgetName : String;
		super.CreateActionWidgetPackage( actions );
		if( IsNameValid( m_atlasTexture ) )
		{
			widgetName = NameToString( m_atlasTexture );
			m_actionWidgetPackage.widgetName = widgetName;
			m_actionWidgetPackage.displayName = widgetName;
		}
	}

	public override function GetInkWidgetLibraryID() : CName
	{
		return '';
	}

	public override function GetInkWidgetTweakDBID() : TweakDBID
	{
		return T"DevicesUIDefinitions.VendorItemActionWidget";
	}

}

struct VendingTerminalSetup
{
	[ customEditor = "TweakDBGroupInheritance;Vendor" ]
	instanceeditable var m_vendorTweakID : TweakDBID;
	const instanceeditable var m_vendingBlacklist : array< EVendorMode >;
	instanceeditable var m_timeToCompletePurchase : Float;
	default m_timeToCompletePurchase = 3.f;
}

class VendingTerminalController extends ScriptableDeviceComponent
{

	public const override function GetPS() : VendingTerminalControllerPS
	{
		return ( ( VendingTerminalControllerPS )( GetBasePS() ) );
	}

}

class VendingTerminalControllerPS extends ScriptableDeviceComponentPS
{
	default m_tweakDBRecord = T"Devices.VendingTerminal";
	default m_tweakDBDescriptionRecord = T"device_descriptions.VendingTerminal";
	private instanceeditable persistent var m_vendingTerminalSetup : VendingTerminalSetup;
	private var m_isReady : Bool;
	private var m_VendorDataManager : VendorDataManager;

	public function Prepare( vendor : weak< GameObject > )
	{
		m_VendorDataManager = new VendorDataManager;
		m_VendorDataManager.Initialize( vendor, m_vendingTerminalSetup );
	}

	public function GetVendorDataManager() : weak< VendorDataManager >
	{
		return m_VendorDataManager;
	}

	public function SetIsReady( value : Bool )
	{
		m_isReady = value;
	}

	public const override function GetBlackboardDef() : VendingMachineDeviceBlackboardDef
	{
		return GetAllBlackboardDefs().VendingMachineDeviceBlackboard;
	}

}

