using Theriapolis.Core.Data;
using Theriapolis.Core.Util;

namespace Theriapolis.Core.World.Generation;

/// <summary>
/// Accumulating context passed through the world-generation pipeline.
/// Holds the WorldState under construction, per-subsystem RNG streams, and a logger.
/// </summary>
public sealed class WorldGenContext
{
    public WorldState World { get; }

    /// <summary>Named RNG sub-streams, keyed by the subsystem constant name.</summary>
    public Dictionary<string, SeededRng> Rngs { get; } = new();

    /// <summary>Directory that holds macro_template.json, biomes.json, etc.</summary>
    public string DataDirectory { get; init; } = "";

    /// <summary>Called after each stage completes: (stageName, progressFraction 0–1).</summary>
    public Action<string, float>? ProgressCallback { get; set; }

    /// <summary>Simple diagnostic log sink.</summary>
    public Action<string>? Log { get; set; }

    public WorldGenContext(ulong seed, string dataDirectory)
    {
        World = new WorldState { WorldSeed = seed };
        DataDirectory = dataDirectory;
    }

    public void ReportProgress(string stageName, float fraction)
        => ProgressCallback?.Invoke(stageName, Math.Clamp(fraction, 0f, 1f));

    public void LogMessage(string msg)
        => Log?.Invoke(msg);
}
