namespace NeonSprawl.Server.Game.Combat;

/// <summary>Maps <c>GET /game/world/ability-definitions</c> (NEO-78).</summary>
public static class AbilityDefinitionsWorldApi
{
    public static WebApplication MapAbilityDefinitionsWorldApi(this WebApplication app)
    {
        app.MapGet(
            "/game/world/ability-definitions",
            (IAbilityDefinitionRegistry registry) =>
            {
                var defs = registry.GetDefinitionsInIdOrder();
                var abilities = new List<AbilityDefinitionJson>(defs.Count);
                foreach (var d in defs)
                {
                    abilities.Add(
                        new AbilityDefinitionJson
                        {
                            Id = d.Id,
                            DisplayName = d.DisplayName,
                            BaseDamage = d.BaseDamage,
                            CooldownSeconds = d.CooldownSeconds,
                            AbilityKind = d.AbilityKind,
                        });
                }

                return Results.Json(
                    new AbilityDefinitionsListResponse
                    {
                        SchemaVersion = AbilityDefinitionsListResponse.CurrentSchemaVersion,
                        Abilities = abilities,
                    });
            });

        return app;
    }
}
