using Baya.Application.Contracts.Common;
using Baya.Application.Features.System.Queries.Ping;
using NSubstitute;

namespace Baya.Test.Foundation;

public class PingQueryHandlerTests
{
    [Fact]
    public async Task Handle_ReturnsSuccess_WithServerTimeFromProvider()
    {
        // Arrange
        var now = new DateTimeOffset(2026, 6, 28, 9, 30, 0, TimeSpan.Zero);
        var clock = Substitute.For<IDateTimeProvider>();
        clock.UtcNow.Returns(now);

        var handler = new PingQueryHandler(clock);

        // Act
        var result = await handler.Handle(new PingQuery(), CancellationToken.None);

        // Assert
        Assert.True(result.IsSuccess);
        Assert.NotNull(result.Result);
        Assert.Equal("ok", result.Result!.Status);
        Assert.Equal(now, result.Result.ServerTimeUtc);
    }
}
