using Indotalent.ConfigBackEnd.Extensions;
using Indotalent.Features.Sales.SalesReport.Cqrs;
using MediatR;
using Microsoft.AspNetCore.Authentication.JwtBearer;

namespace Indotalent.Features.Sales.SalesReport;

public static class SalesReportEndpoint
{
    public static void MapSalesReportEndpoints(this IEndpointRouteBuilder app)
    {
        var group = app.MapGroup("/sales-report").WithTags("SalesReports")
            .RequireAuthorization(policy => policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
            .RequireAuthenticatedUser());

        group.MapGet("/", async (IMediator mediator) =>
        {
            var result = await mediator.Send(new GetSalesReportListQuery());
            return result.ToApiResponse("Sales report list retrieved successfully");
        })
        .WithName("GetSalesReportList");
    }
}