class MaintenancePanelController extends MasterController
{

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

}

class MaintenancePanelControllerPS extends MasterControllerPS
{
	default m_deviceName = "Gameplay-Devices-DisplayNames-MaintenancePanel";
	private instanceeditable inlined var m_maintenancePanelSkillChecks : EngineeringContainer;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
		if( !( IsStringValid( m_deviceName ) ) )
		{
			m_deviceName = "Gameplay-Devices-DisplayNames-MaintenancePanel";
		}
		m_disassembleProperties.m_canBeDisassembled = true;
	}

	protected override function GetSkillCheckContainerForSetup() : BaseSkillCheckContainer
	{
		return m_maintenancePanelSkillChecks;
	}

	protected override function GameAttached() {}

	public function RmoveAuthorizationFromSlaves()
	{
		var i : Int32;
		var putAuthorizationIntoOff : SetAuthorizationModuleOFF;
		var devices : array< DeviceComponentPS >;
		devices = GetImmediateSlaves();
		for( i = 0; i < devices.Size(); i += 1 )
		{
			ExtractActionFromSlave( devices[ i ], 'SetAuthorizationModuleOFF', ( ( DeviceAction )( putAuthorizationIntoOff ) ) );
			if( putAuthorizationIntoOff )
			{
				GetPersistencySystem().QueuePSDeviceEvent( putAuthorizationIntoOff );
			}
		}
	}

	public function RefreshLockOnSlaves()
	{
		var i : Int32;
		var locked : ToggleLock;
		var open : ForceOpen;
		var devices : array< DeviceComponentPS >;
		devices = GetImmediateSlaves();
		for( i = 0; i < devices.Size(); i += 1 )
		{
			ExtractActionFromSlave( devices[ i ], 'ToggleLock', ( ( DeviceAction )( locked ) ) );
			if( locked )
			{
				GetPersistencySystem().QueuePSDeviceEvent( locked );
			}
			ExtractActionFromSlave( devices[ i ], 'ForceOpen', ( ( DeviceAction )( open ) ) );
			if( open )
			{
				GetPersistencySystem().QueuePSDeviceEvent( open );
			}
		}
	}

	protected override function ActionEngineering( const context : ref< GetActionsContext > ) : ActionEngineering
	{
		var action : ActionEngineering;
		var additionalActions : array< DeviceAction >;
		action = super.ActionEngineering( context );
		additionalActions.PushBack( ActionDisassembleDevice() );
		action.CreateInteraction( context.processInitiatorObject, additionalActions );
		return action;
	}

	public override function OnDisassembleDevice( evt : DisassembleDevice ) : EntityNotificationType
	{
		TurnAuthorizationModuleOFF();
		RmoveAuthorizationFromSlaves();
		return super.OnDisassembleDevice( evt );
	}

}

