using Theriapolis.Core.Time;
using Xunit;

namespace Theriapolis.Tests.Entities;

public sealed class WorldClockTests
{
    [Fact]
    public void Advance_AccumulatesSeconds()
    {
        var c = new WorldClock();
        c.Advance(120);
        c.Advance(30);
        Assert.Equal(150, c.InGameSeconds);
    }

    [Fact]
    public void DayHourMinute_DerivedFromSeconds()
    {
        var c = new WorldClock();
        c.Advance(WorldClock.SecondsPerDay * 3 + WorldClock.SecondsPerHour * 14 + WorldClock.SecondsPerMinute * 27);
        Assert.Equal(3, c.Day);
        Assert.Equal(14, c.Hour);
        Assert.Equal(27, c.Minute);
    }

    [Fact]
    public void Season_RotatesWithDays()
    {
        var c = new WorldClock();
        // Advance past one full season (24 days).
        c.Advance(WorldClock.SecondsPerDay * WorldClock.DaysPerSeason + 1);
        Assert.Equal(Season.Summer, c.Season);
    }

    [Fact]
    public void RoundTrip_RestoresState()
    {
        var c = new WorldClock();
        c.Advance(98765);
        var s = c.CaptureState();

        var c2 = new WorldClock();
        c2.RestoreState(s);
        Assert.Equal(98765, c2.InGameSeconds);
    }

    [Fact]
    public void Advance_RejectsNegative()
    {
        var c = new WorldClock();
        Assert.Throws<ArgumentOutOfRangeException>(() => c.Advance(-5));
    }
}
