class ToggleOpenFridge extends ActionBool
{

	public function SetProperties( isOpen : Bool )
	{
		actionName = 'ToggleOpenFridge';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'Open', isOpen, 'LocKey#273', 'LocKey#274' );
	}

}

class FridgeController extends ScriptableDeviceComponent
{

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

}

class FridgeControllerPS extends ScriptableDeviceComponentPS
{
	default m_tweakDBRecord = T"Devices.Fridge";
	default m_tweakDBDescriptionRecord = T"device_descriptions.Fridge";
	default m_deviceName = "LocKey#79";
	private persistent var m_isOpen : Bool;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
		if( !( IsStringValid( m_deviceName ) ) )
		{
			m_deviceName = "LocKey#79";
		}
	}

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

	protected virtual function ActionToggleOpenFridge() : ToggleOpenFridge
	{
		var action : ToggleOpenFridge;
		action = new ToggleOpenFridge;
		action.clearanceLevel = DefaultActionsParametersHolder.GetToggleOpenClearance();
		action.SetUp( this );
		action.SetProperties( m_isOpen );
		action.AddDeviceName( m_deviceName );
		return action;
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		super.GetActions( actions, context );
		if( !( IsUserAuthorized( context.processInitiatorObject.GetEntityID() ) ) )
		{
			return false;
		}
		if( m_deviceState == EDeviceStatus.DISABLED )
		{
			return false;
		}
		if( Clearance.IsInRange( context.clearance, DefaultActionsParametersHolder.GetToggleOpenClearance() ) )
		{
			actions.PushBack( ActionToggleOpenFridge() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	public function OnOpen( evt : ToggleOpenFridge ) : EntityNotificationType
	{
		m_isOpen = !( m_isOpen );
		evt.prop.first = m_isOpen;
		UseNotifier( evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public const override function GetClearance() : Clearance
	{
		return Clearance.CreateClearance( 2, 2 );
	}

	public function IsOpen() : Bool
	{
		return m_isOpen;
	}

}

