namespace NetinaShop.Api.Controller;

public class DashboardController : ICarterModule
{
    public void AddRoutes(IEndpointRouteBuilder app)
    {
        var group = app.NewVersionedApi("Dashboard")
            .MapGroup("api/dashboard")
            .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageDashboard));

        group.MapGet("home", GetHomeDashboardAsync)
            .WithDisplayName("Get Home Dashboard")
            .HasApiVersion(1.0);

    }

    private async Task<IResult> GetHomeDashboardAsync([FromServices] IDashboardService dashboardService, CancellationToken cancellationToken)
        => TypedResults.Ok(await dashboardService.GetHomeDashboardAsyncTask(cancellationToken));
}