using System.Collections.Frozen;

namespace NeonSprawl.Server.Game.Combat;

/// <summary>
/// Prototype E5M1 roster gate (NEO-76 / NEO-77), mirrored from <c>scripts/validate_content.py</c>
/// <c>PROTOTYPE_E5M1_ABILITY_IDS</c> / <c>_prototype_e5m1_ability_gate</c>.
/// </summary>
public static class PrototypeE5M1AbilityCatalogRules
{
    /// <summary>Keep in sync with <c>scripts/validate_content.py</c> <c>PROTOTYPE_E5M1_ABILITY_IDS</c>.</summary>
    public static readonly FrozenSet<string> ExpectedAbilityIds = FrozenSet.ToFrozenSet(
        [
            "prototype_pulse",
            "prototype_guard",
            "prototype_dash",
            "prototype_burst",
        ],
        StringComparer.Ordinal);

    /// <summary>Returns a human-readable error if the E5M1 ability contract fails, otherwise <see langword="null"/>.</summary>
    public static string? TryGetE5M1GateError(IReadOnlyDictionary<string, string> abilityIdToSourceFile)
    {
        var ids = abilityIdToSourceFile.Keys.ToFrozenSet(StringComparer.Ordinal);
        if (!ids.SetEquals(ExpectedAbilityIds))
        {
            return
                "error: prototype E5M1 expects exactly ability ids " +
                $"[{string.Join(", ", ExpectedAbilityIds.Order(StringComparer.Ordinal).Select(s => "'" + s + "'"))}], " +
                $"got [{string.Join(", ", ids.Order(StringComparer.Ordinal).Select(s => "'" + s + "'"))}]";
        }

        return null;
    }
}
