using System.Text.Json;
using FluentAssertions;
using SatelliteProvider.Common.DTO;
using SatelliteProvider.Common.Json;

namespace SatelliteProvider.Tests.Json;

public class UtcOffsetRequiredDateTimeOffsetConverterTests
{
    private static readonly JsonSerializerOptions Options = new()
    {
        PropertyNameCaseInsensitive = true,
        Converters = { new UtcOffsetRequiredDateTimeOffsetConverter() },
    };

    [Theory]
    [InlineData("\"2026-06-26T12:00:00Z\"")]
    [InlineData("\"2026-06-26T12:00:00+00:00\"")]
    [InlineData("\"2026-06-26T12:00:00.1234567Z\"")]
    public void Deserialize_ExplicitUtcOffset_Parses(string capturedAtJson)
    {
        // Arrange
        var json = $$"""{"latitude":50.1,"longitude":36.1,"tileZoom":18,"tileSizeMeters":200,"capturedAt":{{capturedAtJson}}}""";

        // Act
        var metadata = JsonSerializer.Deserialize<UavTileMetadata>(json, Options);

        // Assert
        metadata.Should().NotBeNull();
        metadata!.CapturedAt.Offset.Should().Be(TimeSpan.Zero);
    }

    [Fact]
    public void Deserialize_OffsetLessIsoString_ThrowsJsonException()
    {
        // Arrange
        const string json = """{"latitude":50.1,"longitude":36.1,"tileZoom":18,"tileSizeMeters":200,"capturedAt":"2026-06-26T12:00:00"}""";

        // Act
        var act = () => JsonSerializer.Deserialize<UavTileMetadata>(json, Options);

        // Assert
        act.Should().Throw<JsonException>().WithMessage("*explicit UTC offset*");
    }
}
