using Enmarcha.Backend.Types;
using Enmarcha.Backend.Types.Arrivals;
namespace Enmarcha.Backend.Services;
public class ArrivalsContext
{
///
/// The full GTFS ID of the stop (e.g., "vitrasa:1400")
///
public required string StopId { get; set; }
///
/// The public code of the stop (e.g., "1400")
///
public required string StopCode { get; set; }
///
/// Whether to return a reduced number of arrivals (e.g., 4 instead of 10)
///
public bool IsReduced { get; set; }
///
/// Nano mode: skip all enrichment except real-time estimates.
/// Processors that populate shapes, marquee, next stops, and usage should no-op when true.
///
public bool IsNano { get; set; }
public Position? StopLocation { get; set; }
public required List Arrivals { get; set; }
public List? Usage { get; set; }
public required DateTime NowLocal { get; set; }
}
public interface IArrivalsProcessor
{
///
/// Processes the arrivals in the context. Processors are executed in the order they are registered.
///
Task ProcessAsync(ArrivalsContext context);
}
///
/// Orchestrates the enrichment of arrival data through a series of processors.
/// This follows a pipeline pattern where each step (processor) adds or modifies data
/// in the shared ArrivalsContext.
///
public class ArrivalsPipeline
{
private readonly IEnumerable _processors;
public ArrivalsPipeline(IEnumerable processors)
{
_processors = processors;
}
///
/// Executes all registered processors sequentially.
///
public async Task ExecuteAsync(ArrivalsContext context)
{
using var activity = Telemetry.Source.StartActivity("ArrivalsPipeline");
foreach (var processor in _processors)
{
using var processorActivity = Telemetry.Source.StartActivity($"Processor:{processor.GetType().Name}");
await processor.ProcessAsync(context);
}
}
}