using Predictalytics.Application.Interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

namespace Predictalytics.Api.Endpoints;

public static class AlertEndpoints
{
    public static void MapAlertReadEndpoints(this IEndpointRouteBuilder routes)
    {
        var group = routes.MapGroup("/api/alerts").WithTags("Alerts");

        group.MapGet("/", async (IAlertService svc, int? count, bool? unreadOnly, CancellationToken ct) =>
            Results.Ok(await svc.GetRecentAlertsAsync(count ?? 50, unreadOnly ?? false, ct)));
    }

    public static void MapAlertControlEndpoints(this IEndpointRouteBuilder routes)
    {
        var group = routes.MapGroup("/api/alerts").WithTags("Alerts");

        group.MapPut("/{id:int}/read", async (int id, IAlertService svc, CancellationToken ct) =>
        {
            await svc.MarkAsReadAsync(id, ct);
            return Results.Ok();
        });
    }
}
