namespace Netina.Api.Controllers;

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);

        group.MapGet("orders", GetOrdersDashboardAsync)
            .WithDisplayName("Get Orders Dashboard")
            .HasApiVersion(1.0);


    }

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

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