class DestructibleMasterLightController extends DestructibleMasterDeviceController
{

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

}

class DestructibleMasterLightControllerPS extends DestructibleMasterDeviceControllerPS
{
	default m_deviceName = "LocKey#42165";
	default m_tweakDBRecord = T"Devices.ElectricLight";
	default m_tweakDBDescriptionRecord = T"device_descriptions.ElectricLight";

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

	protected override function GameAttached()
	{
		if( IsDisabled() )
		{
			ForceEnableDevice();
		}
		InitializeCLS();
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		super.GetActions( actions, context );
		if( ToggleON.IsDefaultConditionMet( this, context ) )
		{
			actions.PushBack( ActionToggleON() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	private function InitializeCLS()
	{
		var i : Int32;
		var masters : array< DeviceComponentPS >;
		var fuse : FuseControllerPS;
		var evt : InitializeCLSEvent;
		GetParents( masters );
		for( i = 0; i < masters.Size(); i += 1 )
		{
			fuse = ( ( FuseControllerPS )( masters[ i ] ) );
			if( ( fuse && fuse.IsConnectedToCLS() ) && fuse.IsCLSInitialized() )
			{
				UpdateStateOnCLS( fuse.GetDeviceState() );
			}
			else if( fuse && !( fuse.IsCLSInitialized() ) )
			{
				evt = new InitializeCLSEvent;
				GetPersistencySystem().QueuePSEvent( fuse.GetID(), fuse.GetClassName(), evt );
			}
		}
	}

	private function UpdateStateOnCLS( state : EDeviceStatus )
	{
		if( state == EDeviceStatus.ON )
		{
			if( IsUnpowered() )
			{
				ExecutePSAction( ActionSetDevicePowered(), this );
			}
			ExecutePSAction( ActionSetDeviceON(), this );
		}
		else if( state == EDeviceStatus.OFF )
		{
			ExecutePSAction( ActionSetDeviceOFF(), this );
		}
		else if( state == EDeviceStatus.UNPOWERED )
		{
			ExecutePSAction( ActionSetDeviceUnpowered(), this );
		}
	}

}

