using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Invoices.Queries.GetInvoice;
using Baya.Application.Models.Invoices;
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>The booking's invoice for the customer (tenancy-scoped) or an admin. Read-only.</summary>
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/invoices")]
[Authorize]
[Display(Description = "Booking invoice (customer/admin)")]
public sealed class InvoicesController(ISender sender) : BaseController
{
    [HttpGet("{bookingId}")]
    [ProducesOkApiResponseType<InvoiceDto>]
    public async Task<IActionResult> Get(long bookingId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetInvoiceQuery(bookingId), cancellationToken));
}
