namespace Baya.Domain.Entities.Refunds;

/// <summary>
/// The forward-only allowed-edge table for the <see cref="RefundStatus"/> machine. Every write goes through
/// <see cref="Refund"/>'s cohesive methods, which assert the edge here — an illegal transition is a
/// programming error (the handler pre-checks the expected cases), so the entity fails fast rather than
/// silently overwriting a terminal state.
/// </summary>
public static class RefundTransitions
{
    private static readonly IReadOnlyDictionary<string, IReadOnlyCollection<string>> Allowed =
        new Dictionary<string, IReadOnlyCollection<string>>
        {
            [RefundStatus.Requested] = [RefundStatus.Approved, RefundStatus.Rejected],
            [RefundStatus.Approved] = [RefundStatus.Processing, RefundStatus.Succeeded, RefundStatus.Failed, RefundStatus.Rejected],
            [RefundStatus.Processing] = [RefundStatus.Succeeded, RefundStatus.Failed],
            [RefundStatus.Succeeded] = [],
            [RefundStatus.Failed] = [],
            [RefundStatus.Rejected] = []
        };

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