using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Booking.Commands.AcceptBookingRequest;
using Baya.Application.Features.Booking.Commands.CancelBookingRequest;
using Baya.Application.Features.Booking.Commands.CreateBookingRequest;
using Baya.Application.Features.Booking.Commands.RejectBookingRequest;
using Baya.Application.Features.Booking.Queries.GetBookingRequest;
using Baya.Application.Features.Booking.Queries.ListBookingRequests;
using Baya.Application.Models.Booking;
using Baya.Application.Models.Common;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Baya.Web.Api.Controllers.V1;
///
/// The pre-payment booking-request lifecycle: a customer creates/cancels a request; the assigned nurse
/// accepts/rejects; both parties read their role-scoped inbox and a single request. No money and no
/// bookings row exist here — accept only opens the 30-minute payment window (converted in b9).
///
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize]
[Display(Description = "Pre-payment booking requests (create/accept/reject/cancel + role-scoped inbox)")]
public sealed class BookingRequestsController(ISender sender) : BaseController
{
[HttpPost("[action]")]
[ProducesOkApiResponseType]
public async Task Create(CreateBookingRequestCommand command, CancellationToken cancellationToken)
=> OperationResult(await sender.Send(command, cancellationToken));
[HttpPost("[action]/{id}")]
[ProducesOkApiResponseType]
public async Task Cancel(long id, CancellationToken cancellationToken)
=> OperationResult(await sender.Send(new CancelBookingRequestCommand(id), cancellationToken));
[HttpPost("[action]/{id}")]
[ProducesOkApiResponseType]
public async Task Accept(long id, CancellationToken cancellationToken)
=> OperationResult(await sender.Send(new AcceptBookingRequestCommand(id), cancellationToken));
[HttpPost("[action]/{id}")]
[ProducesOkApiResponseType]
public async Task Reject(long id, RejectBookingRequestCommand command, CancellationToken cancellationToken)
=> OperationResult(await sender.Send(command with { Id = id }, cancellationToken));
[HttpGet("[action]")]
[ProducesOkApiResponseType>]
public async Task List([FromQuery] ListBookingRequestsQuery query, CancellationToken cancellationToken)
=> OperationResult(await sender.Send(query, cancellationToken));
[HttpGet("[action]/{id}")]
[ProducesOkApiResponseType]
public async Task Get(long id, CancellationToken cancellationToken)
=> OperationResult(await sender.Send(new GetBookingRequestQuery(id), cancellationToken));
}