using System.Collections.ObjectModel;

namespace NeonSprawl.Server.Game.Combat;

/// <summary>In-memory ability catalog loaded at startup (NEO-77). Game callers should use <see cref="IAbilityDefinitionRegistry"/>.</summary>
public sealed class AbilityDefinitionCatalog(
    string abilitiesDirectory,
    IReadOnlyDictionary<string, AbilityDefRow> byId,
    int catalogJsonFileCount)
{
    /// <summary>Absolute path to the directory that was enumerated for <c>*_abilities.json</c> catalogs.</summary>
    public string AbilitiesDirectory { get; } = abilitiesDirectory;

    public IReadOnlyDictionary<string, AbilityDefRow> ById { get; } = new ReadOnlyDictionary<string, AbilityDefRow>(new Dictionary<string, AbilityDefRow>(byId, StringComparer.Ordinal));

    public int DistinctAbilityCount => ById.Count;

    /// <summary>Number of <c>*_abilities.json</c> files under <see cref="AbilitiesDirectory"/>.</summary>
    public int CatalogJsonFileCount { get; } = catalogJsonFileCount;

    /// <summary>Resolves a catalog row by stable ability <paramref name="id"/>.</summary>
    public bool TryGetAbility(string id, out AbilityDefRow? row) =>
        ById.TryGetValue(id, out row);
}
