using System;
using MultiWheelC.TrajectoryPlanning.CoarsePath;

namespace MultiWheelC.TrajectoryPlanning.EMPlanner;

public sealed class EmTrajectoryMetadata
{
    public EmTrajectoryMetadata(
        string trajectoryId,
        DateTimeOffset generatedAtUtc,
        DateTimeOffset effectiveAtUtc,
        long mapSnapshotId,
        string referencePathId,
        long vehicleStateSequenceId,
        string previousTrajectoryId,
        int segmentIndex,
        TravelDirection direction,
        EmTerminalType terminalType)
    {
        if (string.IsNullOrWhiteSpace(trajectoryId))
            throw new ArgumentException("A trajectory ID is required.", nameof(trajectoryId));
        if (mapSnapshotId < 0)
            throw new ArgumentOutOfRangeException(nameof(mapSnapshotId));
        if (string.IsNullOrWhiteSpace(referencePathId))
            throw new ArgumentException("A reference path ID is required.", nameof(referencePathId));
        if (vehicleStateSequenceId < 0)
            throw new ArgumentOutOfRangeException(nameof(vehicleStateSequenceId));
        if (segmentIndex < 0)
            throw new ArgumentOutOfRangeException(nameof(segmentIndex));
        if (!Enum.IsDefined(typeof(TravelDirection), direction))
            throw new ArgumentOutOfRangeException(nameof(direction));
        if (!Enum.IsDefined(typeof(EmTerminalType), terminalType))
            throw new ArgumentOutOfRangeException(nameof(terminalType));

        TrajectoryId = trajectoryId;
        GeneratedAtUtc = generatedAtUtc;
        EffectiveAtUtc = effectiveAtUtc;
        MapSnapshotId = mapSnapshotId;
        ReferencePathId = referencePathId;
        VehicleStateSequenceId = vehicleStateSequenceId;
        PreviousTrajectoryId = previousTrajectoryId ?? string.Empty;
        SegmentIndex = segmentIndex;
        Direction = direction;
        TerminalType = terminalType;
    }

    public string TrajectoryId { get; }
    public DateTimeOffset GeneratedAtUtc { get; }
    public DateTimeOffset EffectiveAtUtc { get; }
    public long MapSnapshotId { get; }
    public string ReferencePathId { get; }
    public long VehicleStateSequenceId { get; }
    public string PreviousTrajectoryId { get; }
    public int SegmentIndex { get; }
    public TravelDirection Direction { get; }
    public EmTerminalType TerminalType { get; }
}
