using MediatR;
using Web.Api.Extensions;
using Web.Api.Common;
using Domain.Entities.EmailVerification.ValueObject;

namespace Web.Api.Endpoints.Auth;

internal sealed class ResendEmail : IEndpoint
{
    public sealed record Request(string Email, VerificationType Type);

    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapPost("api/auth/resend-email", async (
            Request request,
            ISender sender,
            CancellationToken ct
        ) =>
        {
            var command = new Application.Features.Api.Auth.ResendEmail.Command(request.Email, request.Type);
            var result = await sender.Send(command, ct);

            return result.Match(
                () => ApiResponse.Ok("이메일 인증번호 재전송 완료"),
                CustomResults.Problem
            );
        })
        .WithTags("Auth")
        .AllowAnonymous();
    }
}
