using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.PartnerCenters.Queries.GetCenterForBooking;
using Baya.Application.Models.PartnerCenters;
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>Internal/admin resolver: which center legally covers a booking (invoice issuer + settlement target).
/// The single merchant-of-record decision — invoices and settlement follow <c>partner_centers</c>.</summary>
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/internal/bookings")]
[Authorize(ConstantPolicies.DynamicPermission)]
[Display(Description = "Internal: resolve the invoice issuer / settlement center for a booking")]
public sealed class InternalCentersController(ISender sender) : BaseController
{
    [HttpGet("{bookingId}/center")]
    [ProducesOkApiResponseType<CenterForBookingDto>]
    public async Task<IActionResult> CenterForBooking(long bookingId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetCenterForBookingQuery(bookingId), cancellationToken));
}
