class PresetTimetableEvent extends Event
{
	var arrayPosition : Int32;
}

abstract class SmartHousePreset extends IScriptable
{
	protected instanceeditable var timetable : SPresetTimetableEntry;

	public virtual function GetPresetName() : CName
	{
		return 'WRONG PRESET';
	}

	public virtual function GetIconName() : CName
	{
		return 'NO ICON';
	}

	public function GetTimeTable() : SPresetTimetableEntry
	{
		return timetable;
	}

	public virtual function ExecutePresetActions( const devices : ref< array< DeviceComponentPS > > )
	{
		var i : Int32;
		for( i = 0; i < devices.Size(); i += 1 )
		{
			if( ( ( SimpleSwitchControllerPS )( devices[ i ] ) ) )
			{
				QueueSwitchActions( ( ( SimpleSwitchControllerPS )( devices[ i ] ) ) );
			}
			else if( ( ( RadioControllerPS )( devices[ i ] ) ) )
			{
				QueueRadioActions( ( ( RadioControllerPS )( devices[ i ] ) ) );
			}
			else if( ( ( TVControllerPS )( devices[ i ] ) ) )
			{
				QueueTVActions( ( ( TVControllerPS )( devices[ i ] ) ) );
			}
			else if( ( ( WindowBlindersControllerPS )( devices[ i ] ) ) )
			{
				QueueWindowBlinderActions( ( ( WindowBlindersControllerPS )( devices[ i ] ) ) );
			}
			else if( ( ( DoorControllerPS )( devices[ i ] ) ) )
			{
				QueueDoorActions( ( ( DoorControllerPS )( devices[ i ] ) ) );
			}
		}
	}

	protected virtual function QueueSwitchActions( device : SimpleSwitchControllerPS ) {}

	protected virtual function QueueRadioActions( device : RadioControllerPS ) {}

	protected virtual function QueueTVActions( device : TVControllerPS ) {}

	protected virtual function QueueWindowBlinderActions( device : WindowBlindersControllerPS ) {}

	protected virtual function QueueDoorActions( device : DoorControllerPS ) {}
}

class MorningPreset extends SmartHousePreset
{

	public override function GetPresetName() : CName
	{
		return 'LocKey#6427';
	}

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

	protected override function QueueSwitchActions( device : SimpleSwitchControllerPS )
	{
		if( device.IsLightSwitch() && device.IsON() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueRadioActions( device : RadioControllerPS )
	{
		if( device.IsOFF() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueTVActions( device : TVControllerPS )
	{
		if( device.IsON() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueWindowBlinderActions( device : WindowBlindersControllerPS )
	{
		if( !( device.IsOpen() ) )
		{
			device.ExecutePSAction( device.ActionToggleOpen(), device );
		}
	}

	protected override function QueueDoorActions( device : DoorControllerPS )
	{
		if( device.IsShutter() )
		{
			if( !( device.IsOpen() ) )
			{
				device.ExecutePSAction( device.ActionToggleOpen(), device );
			}
		}
		else
		{
			if( device.IsLocked() )
			{
				device.ExecutePSAction( device.ActionToggleLock(), device );
			}
		}
	}

}

class EveningPreset extends SmartHousePreset
{

	public override function GetPresetName() : CName
	{
		return 'LocKey#6428';
	}

	protected override function QueueSwitchActions( device : SimpleSwitchControllerPS )
	{
		if( device.IsLightSwitch() && device.IsOFF() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueRadioActions( device : RadioControllerPS )
	{
		if( device.IsON() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueTVActions( device : TVControllerPS )
	{
		if( device.IsOFF() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueWindowBlinderActions( device : WindowBlindersControllerPS )
	{
		if( !( device.IsTilted() ) )
		{
			device.ExecutePSAction( device.ActionToggleTiltBlinders(), device );
		}
	}

	protected override function QueueDoorActions( device : DoorControllerPS )
	{
		if( device.IsShutter() )
		{
			if( !( device.IsOpen() ) )
			{
				device.ExecutePSAction( device.ActionToggleOpen(), device );
			}
		}
		else
		{
			if( device.IsLocked() )
			{
				device.ExecutePSAction( device.ActionToggleLock(), device );
			}
		}
	}

}

class NightPreset extends SmartHousePreset
{

	public override function GetPresetName() : CName
	{
		return 'LocKey#6429';
	}

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

	protected override function QueueSwitchActions( device : SimpleSwitchControllerPS )
	{
		if( device.IsLightSwitch() && device.IsON() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueRadioActions( device : RadioControllerPS )
	{
		if( device.IsON() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueTVActions( device : TVControllerPS )
	{
		if( device.IsON() )
		{
			device.ExecutePSAction( device.ActionToggleON(), device );
		}
	}

	protected override function QueueWindowBlinderActions( device : WindowBlindersControllerPS )
	{
		if( device.IsTilted() )
		{
			device.ExecutePSAction( device.ActionToggleTiltBlinders(), device );
		}
		else if( device.IsOpen() )
		{
			device.ExecutePSAction( device.ActionToggleOpen(), device );
		}
	}

	protected override function QueueDoorActions( device : DoorControllerPS )
	{
		if( device.IsShutter() )
		{
			if( device.IsOpen() )
			{
				device.ExecutePSAction( device.ActionToggleOpen(), device );
			}
		}
		else
		{
			if( !( device.IsLocked() ) )
			{
				device.ExecutePSAction( device.ActionToggleLock(), device );
			}
		}
	}

}

