using System.Diagnostics.CodeAnalysis;

namespace NeonSprawl.Server.Game.Mastery;

/// <summary>Adapter over <see cref="MasteryCatalog"/> (NEO-46).</summary>
public sealed class MasteryCatalogRegistry(MasteryCatalog catalog) : IMasteryCatalogRegistry
{
    /// <inheritdoc />
    public bool TryGetTrack(string? skillId, [NotNullWhen(true)] out MasteryTrackRow? track)
    {
        if (string.IsNullOrEmpty(skillId))
        {
            track = null;
            return false;
        }

        return catalog.TracksBySkillId.TryGetValue(skillId, out track);
    }

    /// <inheritdoc />
    public bool TryGetPerk(string? perkId, [NotNullWhen(true)] out PerkDefRow? perk)
    {
        if (string.IsNullOrEmpty(perkId))
        {
            perk = null;
            return false;
        }

        return catalog.PerksById.TryGetValue(perkId, out perk);
    }

    public IReadOnlyList<MasteryTrackRow> GetTracksInSkillIdOrder() =>
        catalog.TracksBySkillId.Values.OrderBy(t => t.SkillId, StringComparer.Ordinal).ToList();

    public IReadOnlyList<PerkDefRow> GetPerksInIdOrder() =>
        catalog.PerksById.Values.OrderBy(p => p.Id, StringComparer.Ordinal).ToList();
}
