using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Payments.Queries.GetNursePayableBalance;
using Baya.Application.Models.Payments;
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 derived per-nurse payable balance (IRR digit-string), summed from the append-only ledger — never a
/// stored column. Authorized to the nurse themself or an admin/finance role. This is what b13 payouts read.
/// </summary>
[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/nurses")]
[Authorize]
[Display(Description = "Derived nurse payable balance (ledger projection)")]
public sealed class NursePayableBalanceController(ISender sender) : BaseController
{
    [HttpGet("{nurseId}/payable_balance")]
    [ProducesOkApiResponseType<NursePayableBalanceDto>]
    public async Task<IActionResult> PayableBalance(long nurseId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetNursePayableBalanceQuery(nurseId), cancellationToken));
}
