using Theriapolis.Core;
using Theriapolis.Core.Persistence;
using Xunit;

namespace Theriapolis.Tests.Persistence;

/// <summary>
/// Phase 5 M2 refuses Phase-4 saves rather than auto-instantiating a default
/// Character. Verified via <see cref="SaveCodec.IsCompatible"/> +
/// <see cref="SaveCodec.IncompatibilityReason"/>.
/// </summary>
public sealed class V4ToV5MigrationTests
{
    [Fact]
    public void V4Header_IsRejectedAsIncompatible()
    {
        var header = new SaveHeader { Version = 4 };
        Assert.False(SaveCodec.IsCompatible(header));
        Assert.NotEmpty(SaveCodec.IncompatibilityReason(header));
    }

    [Fact]
    public void V5Header_IsCompatible()
    {
        var header = new SaveHeader { Version = 5 };
        Assert.True(SaveCodec.IsCompatible(header));
        Assert.Empty(SaveCodec.IncompatibilityReason(header));
    }

    [Fact]
    public void NewSaveHeader_AutoSetsCurrentSchemaVersion()
    {
        var header = new SaveHeader();
        Assert.Equal(C.SAVE_SCHEMA_VERSION, header.Version);
        Assert.True(header.Version >= C.SAVE_SCHEMA_MIN_VERSION);
    }

    [Fact]
    public void IncompatibilityReason_MentionsVersionInformation()
    {
        var header = new SaveHeader { Version = 3 };
        var reason = SaveCodec.IncompatibilityReason(header);
        Assert.Contains("v3", reason);
        Assert.Contains("v" + C.SAVE_SCHEMA_MIN_VERSION, reason);
    }
}
