using Microsoft.AspNetCore.Http.HttpResults;
using RpgRoller.Contracts;
using RpgRoller.Services;

namespace RpgRoller.Api;

internal static class MeEndpoints
{
    public static RouteGroupBuilder MapMeEndpoints(this RouteGroupBuilder group)
    {
        group.MapGet("/me", Results<Ok<MeResponse>, BadRequest<ApiError>, UnauthorizedHttpResult> (HttpContext context, IGameService game) =>
        {
            var result = game.GetMe(context.GetRequiredSessionToken());
            return ApiResultMapper.ToApiResult(result);
        });

        return group;
    }
}