using System.Linq;
using System.Net;
using System.Net.Http.Json;
using NeonSprawl.Server.Game.Gigs;
using Xunit;

namespace NeonSprawl.Server.Tests.Game.Gigs;

public sealed class GigProgressionSnapshotApiTests
{
    [Fact]
    public async Task GetGigProgression_ShouldReturnNotFound_WhenPlayerUnknown()
    {
        // Arrange
        await using var factory = new InMemoryWebApplicationFactory();
        var client = factory.CreateClient();

        // Act
        var response = await client.GetAsync("/game/players/missing-player/gig-progression");

        // Assert
        Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
    }

    [Fact]
    public async Task GetGigProgression_ShouldReturnSchemaV1_WithDefaultXpAndLevel_ForPrototypeMainGig()
    {
        // Arrange
        await using var factory = new InMemoryWebApplicationFactory();
        var client = factory.CreateClient();

        // Act
        var response = await client.GetAsync("/game/players/dev-local-1/gig-progression");

        // Assert
        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        var body = await response.Content.ReadFromJsonAsync<GigProgressionSnapshotResponse>();
        Assert.NotNull(body);
        Assert.Equal(GigProgressionSnapshotResponse.CurrentSchemaVersion, body!.SchemaVersion);
        Assert.Equal("dev-local-1", body.PlayerId);
        Assert.Equal(GigProgressionConstants.PrototypeMainGigId, body.MainGigId);
        Assert.NotNull(body.Gigs);
        var breach = Assert.Single(body.Gigs!);
        Assert.Equal(GigProgressionConstants.PrototypeMainGigId, breach.Id);
        Assert.Equal(0, breach.Xp);
        Assert.Equal(GigProgressionConstants.PrototypeFixedLevel, breach.Level);
    }
}
