enum EFastTravelTriggerType
{
	Manual = 0,
	Auto = 1,
}

enum EFastTravelDeviceType
{
	DataTerm = 0,
	SubwayGate = 1,
}

class DataTermController extends ScriptableDeviceComponent
{

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

}

class FastTravelDeviceAction extends ActionBool
{
	private var m_fastTravelPointData : FastTravelPointData;

	public function SetProperties( data : FastTravelPointData )
	{
		var displayName : CName;
		m_fastTravelPointData = data;
		displayName = StringToName( TweakDBInterface.GetFastTravelPointRecord( data.GetPointRecord() ).DisplayName() );
		actionName = 'FastTravel';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'FastTravel', true, displayName, displayName );
	}

	public static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		if( IsAvailable( device ) && IsClearanceValid( context.clearance ) )
		{
			return true;
		}
		return false;
	}

	public static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		if( device.IsUnpowered() || device.IsDisabled() )
		{
			return false;
		}
		return true;
	}

	public static function IsClearanceValid( clearance : Clearance ) : Bool
	{
		if( Clearance.IsInRange( clearance, DefaultActionsParametersHolder.GetQuestClearance() ) )
		{
			return true;
		}
		return false;
	}

	public override function CreateActionWidgetPackage( optional actions : array< DeviceAction > )
	{
		var widgetName : String;
		widgetName = TweakDBInterface.GetFastTravelPointRecord( m_fastTravelPointData.GetPointRecord() ).DisplayName();
		super.CreateActionWidgetPackage( actions );
		m_actionWidgetPackage.widgetName = widgetName;
	}

	public const function GetFastTravelPointData() : FastTravelPointData
	{
		return m_fastTravelPointData;
	}

}

class OpenWorldMapDeviceAction extends ActionBool
{
	private var m_fastTravelPointData : FastTravelPointData;

	public function SetProperties()
	{
		actionName = 'OpenWorldMapDeviceAction';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( 'OpenWorldMapDeviceAction', true, 'LocKey#2057', 'LocKey#2057' );
	}

	public static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		if( IsAvailable( device ) && IsClearanceValid( context.clearance ) )
		{
			return true;
		}
		return false;
	}

	public static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		if( device.IsUnpowered() || device.IsDisabled() )
		{
			return false;
		}
		return true;
	}

	public static function IsClearanceValid( clearance : Clearance ) : Bool
	{
		if( Clearance.IsInRange( clearance, DefaultActionsParametersHolder.GetQuestClearance() ) )
		{
			return true;
		}
		return false;
	}

	public override function GetTweakDBChoiceRecord() : String
	{
		return "SellectDestination";
	}

}

class DataTermControllerPS extends ScriptableDeviceComponentPS
{
	default m_tweakDBRecord = T"Devices.DataTerm";
	default m_tweakDBDescriptionRecord = T"device_descriptions.DataTerm";
	private var m_linkedFastTravelPoint : FastTravelPointData;
	private editable var m_triggerType : EFastTravelTriggerType;
	default m_triggerType = EFastTravelTriggerType.Manual;
	private editable var m_fastTravelDeviceType : EFastTravelDeviceType;
	default m_fastTravelDeviceType = EFastTravelDeviceType.DataTerm;

	public const function GetFastravelTriggerType() : EFastTravelTriggerType
	{
		return m_triggerType;
	}

	public const function GetFastravelDeviceType() : EFastTravelDeviceType
	{
		return m_fastTravelDeviceType;
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		if( !( super.GetActions( actions, context ) ) )
		{
			return false;
		}
		if( context.processInitiatorObject && !( IsUserAuthorized( context.processInitiatorObject.GetEntityID() ) ) )
		{
			return false;
		}
		if( ( GetFastravelTriggerType() == EFastTravelTriggerType.Manual && GetFastravelDeviceType() != EFastTravelDeviceType.SubwayGate ) && GetFastTravelSystem().IsFastTravelEnabled() )
		{
			actions.PushBack( ActionOpenWorldMap() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	public const override function GetBlackboardDef() : DataTermDeviceBlackboardDef
	{
		return GetAllBlackboardDefs().DataTermDeviceBlackboard;
	}

	protected function ActionFastTravel( actionData : FastTravelPointData ) : FastTravelDeviceAction
	{
		var action : FastTravelDeviceAction;
		action = new FastTravelDeviceAction;
		action.SetUp( this );
		action.SetProperties( actionData );
		action.AddDeviceName( m_deviceName );
		action.CreateActionWidgetPackage();
		return action;
	}

	public virtual function OnFastTravelAction( evt : FastTravelDeviceAction ) : EntityNotificationType
	{
		var notifier : ActionNotifier;
		notifier = new ActionNotifier;
		notifier.SetNone();
		if( IsUnpowered() || IsDisabled() )
		{
			return SendActionFailedEvent( evt, evt.GetRequesterID(), "Unpowered or Disabled" );
		}
		if( !( IsFinal() ) )
		{
		}
		Notify( notifier, evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	protected function ActionOpenWorldMap() : OpenWorldMapDeviceAction
	{
		var action : OpenWorldMapDeviceAction;
		action = new OpenWorldMapDeviceAction;
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		action.CreateActionWidgetPackage();
		action.CreateInteraction();
		return action;
	}

	public virtual function OnOpenWorldMapAction( evt : OpenWorldMapDeviceAction ) : EntityNotificationType
	{
		var notifier : ActionNotifier;
		notifier = new ActionNotifier;
		notifier.SetNone();
		if( IsUnpowered() || IsDisabled() )
		{
			return SendActionFailedEvent( evt, evt.GetRequesterID(), "Unpowered or Disabled" );
		}
		if( !( IsFinal() ) )
		{
		}
		Notify( notifier, evt );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public function SetLinkedFastTravelPoint( point : FastTravelPointData )
	{
		m_linkedFastTravelPoint = point;
	}

	private function GetFastTravelSystem() : FastTravelSystem
	{
		return ( ( FastTravelSystem )( GameInstance.GetScriptableSystemsContainer( GetGameInstance() ).Get( 'FastTravelSystem' ) ) );
	}

}

