namespace NeonSprawl.Server.Game.Skills;

/// <summary>Maps <c>GET /game/world/skill-definitions</c> (NEO-36).</summary>
public static class SkillDefinitionsWorldApi
{
    public static WebApplication MapSkillDefinitionsWorldApi(this WebApplication app)
    {
        app.MapGet(
            "/game/world/skill-definitions",
            (ISkillDefinitionRegistry registry) =>
            {
                var defs = registry.GetDefinitionsInIdOrder();
                var skills = new List<SkillDefinitionJson>(defs.Count);
                foreach (var d in defs)
                {
                    skills.Add(
                        new SkillDefinitionJson
                        {
                            Id = d.Id,
                            DisplayName = d.DisplayName,
                            Category = d.Category,
                            AllowedXpSourceKinds = d.AllowedXpSourceKinds,
                        });
                }

                return Results.Json(
                    new SkillDefinitionsListResponse
                    {
                        SchemaVersion = SkillDefinitionsListResponse.CurrentSchemaVersion,
                        Skills = skills,
                    });
            });

        return app;
    }
}
