using Theriapolis.Core.World.Generation;
using Xunit;

namespace Theriapolis.Tests.Determinism;

/// <summary>
/// Phase 2+3 determinism contract: same seed → identical settlements and polylines.
/// Uses variant 0 and variant 1 so the fixture returns two independent pipeline
/// runs rather than comparing one cached context to itself.
/// </summary>
public sealed class Phase23DeterminismTests : IClassFixture<WorldCache>
{
    private const ulong TestSeed = 0xCAFEBABEUL;
    private readonly WorldCache _cache;

    public Phase23DeterminismTests(WorldCache cache) => _cache = cache;

    [Fact]
    public void SameSeed_ProducesIdenticalSettlements()
    {
        var h1 = _cache.Get(TestSeed, variant: 0).World.HashSettlements();
        var h2 = _cache.Get(TestSeed, variant: 1).World.HashSettlements();
        Assert.Equal(h1, h2);
    }

    [Fact]
    public void SameSeed_ProducesIdenticalPolylines()
    {
        var h1 = _cache.Get(TestSeed, variant: 0).World.HashPolylines();
        var h2 = _cache.Get(TestSeed, variant: 1).World.HashPolylines();
        Assert.Equal(h1, h2);
    }

    [Fact]
    public void DifferentSeeds_ProduceDifferentSettlements()
    {
        var h1 = _cache.Get(TestSeed).World.HashSettlements();
        var h2 = _cache.Get(TestSeed + 7).World.HashSettlements();
        Assert.NotEqual(h1, h2);
    }

    [Theory]
    [InlineData(0xABCD1234UL)]
    [InlineData(0x00000001UL)]
    [InlineData(0xDEADBEEFUL)]
    public void MultipleSeeds_SettlementsAreDeterministic(ulong seed)
    {
        var h1 = _cache.Get(seed, variant: 0).World.HashSettlements();
        var h2 = _cache.Get(seed, variant: 1).World.HashSettlements();
        Assert.Equal(h1, h2);
    }
}
