using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Booking.Commands.ExpireBookingRequests;
using Baya.Application.Models.Booking;
using Baya.Infrastructure.Identity.Identity.PermissionManager;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Baya.Web.Api.Controllers.V1;

/// <summary>
/// Admin manual trigger for the booking-request expiry sweep — fires the same idempotent command the
/// recurring <c>BackgroundService</c> runs, so a human/test can expire stale requests on demand without
/// waiting for the interval.
/// </summary>
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize(ConstantPolicies.DynamicPermission)]
[Display(Description = "Admin booking-request maintenance (manual expiry sweep)")]
public sealed class AdminBookingRequestsController(ISender sender) : BaseController
{
    [HttpPost("[action]")]
    [ProducesOkApiResponseType<ExpireBookingRequestsResult>]
    public async Task<IActionResult> Expire(CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new ExpireBookingRequestsCommand(), cancellationToken));
}
