namespace Baya.Domain.Entities.Booking;

/// <summary>
/// The allowed status machine for <see cref="BookingSession"/>. A scheduled visit can start (check-in),
/// be cancelled, or be marked missed (no-show sweep); an in-progress visit can complete (check-out) or be
/// cancelled. Completed/missed/cancelled are terminal.
/// </summary>
public static class BookingSessionTransitions
{
    private static readonly IReadOnlyDictionary<string, IReadOnlyCollection<string>> Allowed =
        new Dictionary<string, IReadOnlyCollection<string>>
        {
            [BookingSessionStatus.Scheduled] =
            [
                BookingSessionStatus.InProgress,
                BookingSessionStatus.Cancelled,
                BookingSessionStatus.Missed
            ],
            [BookingSessionStatus.InProgress] =
            [
                BookingSessionStatus.Completed,
                BookingSessionStatus.Cancelled
            ],
            [BookingSessionStatus.Completed] = [],
            [BookingSessionStatus.Missed] = [],
            [BookingSessionStatus.Cancelled] = []
        };

    public static bool CanTransition(string from, string to)
        => Allowed.TryGetValue(from, out var targets) && targets.Contains(to);
}
