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

namespace Baya.Web.Api.Controllers.V1;

/// <summary>Admin-only invoice issuance. Issuing an invoice draws the next sequential number, computes VAT on
/// the commission line from config, and submits to (mocked) مودیان. Idempotent per booking.</summary>
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/admin_invoices")]
[Authorize(ConstantPolicies.DynamicPermission)]
[EnableRateLimiting(RateLimitingServiceExtension.SensitivePolicy)]
[Display(Description = "Admin invoice issuance")]
public sealed class AdminInvoicesController(ISender sender) : BaseController
{
    [HttpPost]
    [ProducesOkApiResponseType<InvoiceDto>]
    public async Task<IActionResult> Issue(IssueInvoiceCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));
}
