using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Refunds.Commands.WriteOffClawback;
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 nurse-clawback management. Write-off marks a pending receivable uncollectable and posts
/// the balancing bad-debt correction; recovery via payout netting is b13.</summary>
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/admin_clawbacks")]
[Authorize(ConstantPolicies.DynamicPermission)]
[EnableRateLimiting(RateLimitingServiceExtension.SensitivePolicy)]
[Display(Description = "Admin nurse-clawback write-off")]
public sealed class AdminClawbacksController(ISender sender) : BaseController
{
    [HttpPost("{id}/[action]")]
    [ProducesOkApiResponseType<bool>]
    public async Task<IActionResult> WriteOff(long id, WriteOffClawbackBody body, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new WriteOffClawbackCommand(id, body.Reason), cancellationToken));
}

/// <summary>The write-off body (the id comes from the route).</summary>
public record WriteOffClawbackBody(string Reason);
