using FluentAssertions;
using SatelliteProvider.Common.Enums;

namespace SatelliteProvider.Tests;

public class TileSourceConverterTests
{
    [Theory]
    [InlineData(TileSource.GoogleMaps, "google_maps")]
    [InlineData(TileSource.Uav, "uav")]
    public void ToWireValue_EmitsContractWireValue_AZ484(TileSource value, string expected)
    {
        // Act
        var result = TileSourceConverter.ToWireValue(value);

        // Assert
        result.Should().Be(expected);
    }

    [Theory]
    [InlineData("google_maps", TileSource.GoogleMaps)]
    [InlineData("GOOGLE_MAPS", TileSource.GoogleMaps)]
    [InlineData("uav", TileSource.Uav)]
    [InlineData("UAV", TileSource.Uav)]
    public void FromWireValue_AcceptsContractWireValue_AZ484(string raw, TileSource expected)
    {
        // Act
        var result = TileSourceConverter.FromWireValue(raw);

        // Assert
        result.Should().Be(expected);
    }

    [Theory]
    [InlineData(TileSource.GoogleMaps)]
    [InlineData(TileSource.Uav)]
    public void RoundTrip_PreservesValue_AZ484(TileSource value)
    {
        // Act
        var roundTripped = TileSourceConverter.FromWireValue(TileSourceConverter.ToWireValue(value));

        // Assert
        roundTripped.Should().Be(value);
    }

    [Fact]
    public void FromWireValue_UnknownString_ThrowsArgumentException_AZ484()
    {
        // Act
        Action act = () => TileSourceConverter.FromWireValue("satar");

        // Assert — Inv-1: unknown sources surface, not silently coerce (coderule.mdc: never suppress errors).
        act.Should().Throw<ArgumentException>().WithMessage("*satar*");
    }

    [Fact]
    public void FromWireValue_NullValue_ThrowsArgumentNullException_AZ484()
    {
        // Act
        Action act = () => TileSourceConverter.FromWireValue(null!);

        // Assert
        act.Should().Throw<ArgumentNullException>();
    }

    [Theory]
    [InlineData("google_maps", true)]
    [InlineData("uav", true)]
    [InlineData("GoogleMaps", false)]
    [InlineData("satar", false)]
    [InlineData("", false)]
    [InlineData(null, false)]
    public void IsValidWireValue_OnlyExactWireValuesPass_AZ484(string? raw, bool expected)
    {
        // Act
        var result = TileSourceConverter.IsValidWireValue(raw);

        // Assert
        result.Should().Be(expected);
    }
}
