using PepperDash.Core;
using Serilog.Events;
using System;
namespace PepperDash.Essentials.Core
{
///
/// Represents a request to establish a route between a source and a destination device.
///
public class RouteRequest
{
///
/// The specific input port on the destination device to use for the route. Can be null if the port should be automatically determined or is not applicable.
///
public RoutingInputPort DestinationPort { get; set; }
///
/// The specific output port on the source device to use for the route. Can be null if the port should be automatically determined or is not applicable.
///
public RoutingOutputPort SourcePort { get; set; }
///
/// The destination device (sink or midpoint) for the route.
///
public IRoutingInputs Destination { get; set; }
///
/// The source device for the route.
///
public IRoutingOutputs Source { get; set; }
///
/// The type of signal being routed (e.g., Audio, Video, AudioVideo).
///
public eRoutingSignalType SignalType { get; set; }
///
/// Handles the route request after a device's cooldown period has finished.
/// This method is typically subscribed to the IsCoolingDownFeedback.OutputChange event.
///
/// The object that triggered the event (usually the cooling device).
/// Event arguments indicating the cooldown state change.
public void HandleCooldown(object sender, FeedbackEventArgs args)
{
try
{
Debug.LogMessage(LogEventLevel.Information, "Handling cooldown route request: {destination}:{destinationPort} -> {source}:{sourcePort} {type}", null, Destination?.Key ?? "empty destination", DestinationPort?.Key ?? "no destination port", Source?.Key ?? "empty source", SourcePort?.Key ?? "empty source port", SignalType.ToString());
if (args.BoolValue == true)
{
return;
}
Debug.LogMessage(LogEventLevel.Information, "Cooldown complete. Making route from {destination} to {source}", Destination?.Key, Source?.Key);
Destination.ReleaseAndMakeRoute(Source, SignalType, DestinationPort?.Key ?? string.Empty, SourcePort?.Key ?? string.Empty);
if (sender is IWarmingCooling coolingDevice)
{
Debug.LogMessage(LogEventLevel.Debug, "Unsubscribing from cooling feedback for {destination}", null, Destination.Key);
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
}
} catch(Exception ex)
{
Debug.LogMessage(ex, "Exception handling cooldown", Destination);
}
}
///
/// Returns a string representation of the route request.
///
/// A string describing the source and destination of the route request.
public override string ToString()
{
return $"Route {Source?.Key ?? "No Source Device"}:{SourcePort?.Key ?? "auto"} to {Destination?.Key ?? "No Destination Device"}:{DestinationPort?.Key ?? "auto"}";
}
}
}