using FluentAssertions;
using SatelliteProvider.Common.Configs;
using SatelliteProvider.Services.TileDownloader;

namespace SatelliteProvider.Tests;

public class UavTileFilePathTests
{
    [Theory]
    [InlineData("./tiles", 18, 76800, 50331)]
    [InlineData("/var/lib/sat/tiles", 16, 12345, 67890)]
    public void BuildUavTileFilePath_AnonymousFlight_UsesNoneSegment(string root, int zoom, int x, int y)
    {
        // Arrange
        var storage = new StorageConfig { TilesDirectory = root };

        // Act
        var path = UavTileUploadHandler.BuildUavTileFilePath(storage, zoom, x, y);

        // Assert
        var expected = Path.Combine(root, "uav", "none", zoom.ToString(), x.ToString(), y + ".jpg");
        path.Should().Be(expected,
            "AZ-503: flight-anonymous UAV paths use the literal `none` segment so they are visually distinct from real flight directories during ops triage");
    }

    [Theory]
    [InlineData("./tiles", 18, 76800, 50331, "11111111-2222-3333-4444-555555555555")]
    [InlineData("/var/lib/sat/tiles", 16, 12345, 67890, "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")]
    public void BuildUavTileFilePath_PerFlight_UsesFlightIdDirectory(string root, int zoom, int x, int y, string flightIdString)
    {
        // Arrange
        var storage = new StorageConfig { TilesDirectory = root };
        var flightId = Guid.Parse(flightIdString);

        // Act
        var path = UavTileUploadHandler.BuildUavTileFilePath(storage, zoom, x, y, flightId);

        // Assert
        var expected = Path.Combine(root, "uav", flightIdString, zoom.ToString(), x.ToString(), y + ".jpg");
        path.Should().Be(expected,
            "AZ-503 AC-11: UAV file paths follow `./tiles/uav/{flight_id}/{zoom}/{x}/{y}.jpg` so per-flight evidence is structurally isolated on disk");
    }

    [Fact]
    public void BuildUavTileFilePath_DifferentFlights_ProduceDifferentPaths()
    {
        // Arrange
        var storage = new StorageConfig { TilesDirectory = "./tiles" };
        var f1 = Guid.Parse("11111111-1111-1111-1111-111111111111");
        var f2 = Guid.Parse("22222222-2222-2222-2222-222222222222");

        // Act
        var p1 = UavTileUploadHandler.BuildUavTileFilePath(storage, 18, 100, 200, f1);
        var p2 = UavTileUploadHandler.BuildUavTileFilePath(storage, 18, 100, 200, f2);

        // Assert
        p1.Should().NotBe(p2, "AZ-503 AC-11: two flights uploading the same (z, x, y) cell must land at distinct paths");
        p1.Should().Contain(f1.ToString());
        p2.Should().Contain(f2.ToString());
    }
}
