using Application.Abstractions.Messaging;
using Web.Api.Common;
using Web.Api.Extensions;

namespace Web.Api.Endpoints.MyPage;

internal sealed class VerifyEmail : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/mypage/email/verify", async (
            string token,
            ISender sender,
            CancellationToken ct
        ) => {
            var query = new Application.Features.Api.MyPage.VerifyEmail.Query(token);
            var result = await sender.Send(query, ct);

            return result.Match(
                () => ApiResponse.Ok(),
                CustomResults.Problem
            );
        })
        .WithTags("MyPage")
        .AllowAnonymous();
    }
}