using System.Collections.ObjectModel;

namespace NeonSprawl.Server.Game.Crafting;

/// <summary>In-memory recipe catalog loaded at startup (NEO-66). Game callers should use <see cref="IRecipeDefinitionRegistry"/> (NEO-67).</summary>
public sealed class RecipeDefinitionCatalog(
    string recipesDirectory,
    IReadOnlyDictionary<string, RecipeDefRow> byId,
    int catalogJsonFileCount)
{
    /// <summary>Absolute path to the directory that was enumerated for <c>*_recipes.json</c> catalogs.</summary>
    public string RecipesDirectory { get; } = recipesDirectory;

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

    public int DistinctRecipeCount => ById.Count;

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

    /// <summary>Resolves a catalog row by stable recipe <paramref name="id"/> (includes embedded I/O rows).</summary>
    public bool TryGetRecipe(string id, out RecipeDefRow? row) =>
        ById.TryGetValue(id, out row);
}
