class UseSecurityLocker extends ActionBool
{

	public function SetProperties( shouldDeposit : Bool )
	{
		actionName = 'UseSecurityLocker';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( actionName, shouldDeposit, 'LocKey#286', 'LocKey#287' );
	}

	public override function GetTweakDBChoiceRecord() : String
	{
		if( !( ( ( Bool )prop.first ) ) )
		{
			return "DepositWeapons";
		}
		else
		{
			return "RetrieveWeapons";
		}
	}

}

struct SecurityLockerProperties
{
	[ tooltip = "What access should be given to the palyer if deposits weapons and deactivates cyberwere. Note this works only if Security Locker is connected to Security System" ]
	instanceeditable var securityLevelAccessGranted : ESecurityAccessLevel;
	default securityLevelAccessGranted = ESecurityAccessLevel.ESL_4;
	[ tooltip = "Should disable player's combat cyberware on top of taking weapons away? Will trigger personal link animation" ]
	instanceeditable var disableCyberware : Bool;
	[ customEditor = "AudioEvent" ]
	editable var storeWeaponSFX : CName;
	default storeWeaponSFX = 'ui_loot_gun';
	[ customEditor = "AudioEvent" ]
	editable var pickUpWeaponSFX : CName;
	default pickUpWeaponSFX = 'ui_loot_take_all';
}

class SecurityLockerController extends ScriptableDeviceComponent
{

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

}

struct SecurityLockerUserEntry
{
}

class SecurityLockerControllerPS extends ScriptableDeviceComponentPS
{
	default m_deviceName = "LocKey#122";
	private instanceeditable var m_securityLockerProperties : SecurityLockerProperties;
	private persistent var m_isStoringPlayerEquipement : Bool;

	public const function ShouldDisableCyberware() : Bool
	{
		return m_securityLockerProperties.disableCyberware;
	}

	public const function GetAuthorizationLevel() : ESecurityAccessLevel
	{
		return m_securityLockerProperties.securityLevelAccessGranted;
	}

	public quest const function GetIsEmpty() : Bool
	{
		return !( m_isStoringPlayerEquipement );
	}

	public export quest const function GetIsStoringPlayerEquipement() : Bool
	{
		return m_isStoringPlayerEquipement;
	}

	public const function GetStoreSFX() : CName
	{
		return m_securityLockerProperties.storeWeaponSFX;
	}

	public const function GetReturnSFX() : CName
	{
		return m_securityLockerProperties.pickUpWeaponSFX;
	}

	protected override function Initialize()
	{
		super.Initialize();
	}

	private function ActionUseSecurityLocker( executor : GameObject ) : UseSecurityLocker
	{
		var action : UseSecurityLocker;
		action = new UseSecurityLocker;
		action.clearanceLevel = DefaultActionsParametersHolder.GetInteractiveClearance();
		action.SetProperties( m_isStoringPlayerEquipement );
		action.SetExecutor( executor );
		action.SetUp( this );
		action.AddDeviceName( GetDeviceName() );
		action.CreateInteraction();
		return action;
	}

	public function OnUseSecurityLocker( evt : UseSecurityLocker ) : EntityNotificationType
	{
		var togglePersonalLink : TogglePersonalLink;
		if( ShouldDisableCyberware() )
		{
			togglePersonalLink = ActionTogglePersonalLink( evt.GetExecutor() );
			togglePersonalLink.SetIllegal( false );
			ExecutePSAction( togglePersonalLink, evt.GetInteractionLayer() );
			return EntityNotificationType.DoNotNotifyEntity;
		}
		m_isStoringPlayerEquipement = !( m_isStoringPlayerEquipement );
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	protected override function ResolvePersonalLinkConnection( evt : TogglePersonalLink, abortOperation : Bool )
	{
		super.ResolvePersonalLinkConnection( evt, abortOperation );
		if( abortOperation )
		{
			return;
		}
		QueueEntityEvent( GetMyEntityID(), ActionUseSecurityLocker( evt.GetExecutor() ) );
		m_isStoringPlayerEquipement = !( m_isStoringPlayerEquipement );
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		if( !( super.GetActions( actions, context ) ) )
		{
			return false;
		}
		if( IsON() && context.requestType == gamedeviceRequestType.Direct )
		{
			if( !( IsPersonalLinkConnected() ) && !( IsPersonalLinkConnecting() ) )
			{
				actions.PushBack( ActionUseSecurityLocker( context.processInitiatorObject ) );
			}
		}
		return true;
	}

	protected override function GetDeviceIconTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.SecuritySystemDeviceIcon";
	}

	protected override function GetBackgroundTextureTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.SecuritySystemDeviceBackground";
	}

}

