using FastEndpoints;
using SpaceGame.Api.Universe.Bootstrap;

namespace SpaceGame.Api.Auth.Api;

public sealed class GetRacesHandler(IStaticDataProvider staticData) : EndpointWithoutRequest<IReadOnlyList<RaceSnapshot>>
{
    public override void Configure()
    {
        Get("/api/auth/races");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CancellationToken cancellationToken)
    {
        var races = staticData.RaceDefinitions.Values
          .OrderBy(race => race.Name, StringComparer.Ordinal)
          .Select(race => new RaceSnapshot(race.Id, race.Name, race.Description, race.Icon))
          .ToList();
        await SendOkAsync(races, cancellationToken);
    }
}
