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

namespace NeonSprawl.Server.Tests.Game.Skills;

public class SkillDefinitionsWorldApiTests
{
    [Fact]
    public async Task GetSkillDefinitions_ShouldReturnSchemaV1_WithFrozenTrioInIdOrder()
    {
        // Arrange
        await using var factory = new InMemoryWebApplicationFactory();
        var client = factory.CreateClient();
        // Act
        var response = await client.GetAsync("/game/world/skill-definitions");
        // Assert
        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        var body = await response.Content.ReadFromJsonAsync<SkillDefinitionsListResponse>();
        Assert.NotNull(body);
        Assert.Equal(SkillDefinitionsListResponse.CurrentSchemaVersion, body!.SchemaVersion);
        Assert.NotNull(body.Skills);
        var ids = body.Skills.Select(static s => s.Id).ToList();
        Assert.Equal(new[] { "intrusion", "refine", "salvage" }, ids);

        var salvage = body.Skills.Single(s => s.Id == "salvage");
        Assert.Equal("Salvage", salvage.DisplayName);
        Assert.Equal("gather", salvage.Category);
        Assert.Equal(new[] { "activity", "mission_reward" }, salvage.AllowedXpSourceKinds);

        var refine = body.Skills.Single(s => s.Id == "refine");
        Assert.Contains("trainer", refine.AllowedXpSourceKinds);

        var intrusion = body.Skills.Single(s => s.Id == "intrusion");
        Assert.Contains("book_or_item", intrusion.AllowedXpSourceKinds);
    }
}
