namespace RolemasterDb.ImportTool.Parsing;

internal sealed class AffixLegend
{
    public static AffixLegend Empty { get; } = new(
        new Dictionary<string, string>(StringComparer.Ordinal),
        [],
        supportsFoePenalty: false,
        supportsAttackerBonus: false,
        supportsPowerPointModifier: false);

    public AffixLegend(
        IReadOnlyDictionary<string, string> symbolEffects,
        IReadOnlyCollection<string> classificationOnlySymbols,
        bool supportsFoePenalty,
        bool supportsAttackerBonus,
        bool supportsPowerPointModifier)
    {
        SymbolEffects = new Dictionary<string, string>(symbolEffects, StringComparer.Ordinal);
        EffectSymbols = new HashSet<string>(SymbolEffects.Keys, StringComparer.Ordinal);

        var classificationSymbols = new HashSet<string>(EffectSymbols, StringComparer.Ordinal);
        foreach (var symbol in classificationOnlySymbols)
        {
            classificationSymbols.Add(symbol);
        }

        ClassificationSymbols = classificationSymbols;
        SupportsFoePenalty = supportsFoePenalty;
        SupportsAttackerBonus = supportsAttackerBonus;
        SupportsPowerPointModifier = supportsPowerPointModifier;
    }

    public IReadOnlyDictionary<string, string> SymbolEffects { get; }

    public IReadOnlySet<string> EffectSymbols { get; }

    public IReadOnlySet<string> ClassificationSymbols { get; }

    public bool SupportsFoePenalty { get; }

    public bool SupportsAttackerBonus { get; }

    public bool SupportsPowerPointModifier { get; }

    public string? ResolveEffectCode(string symbol) =>
        SymbolEffects.TryGetValue(symbol, out var effectCode)
            ? effectCode
            : null;
}
