using Fitness_core_BE.Helpers; using Fitness_core_BE.Interfaces.Services; using Fitness_core_BE.Models.IOs; using Microsoft.AspNetCore.Mvc; using static Fitness_core_BE.Helpers.JwtMiddleware; using static Fitness_core_BE.Helpers.ApiResponseHelper; namespace Fitness_core_BE.Controllers { public record ChangeRenewalPlanRequest(Guid NewCustomerPlanId); // Staff-facing approval queue for the unapproved (IsActive=false) invoices the daily // SubscriptionRenewalJob sweep creates. See ISubscriptionRenewalApprovalService. [ApiController] [Route("api/client/renewal-approvals")] [CustomMiddleware] [TenantResolution] [RequiresPermission("customer-payments")] public class SubscriptionRenewalApprovalController(ISubscriptionRenewalApprovalService approvalService) : ControllerBase { private readonly ISubscriptionRenewalApprovalService _approvalService = approvalService; [HttpGet] public async Task>> GetUnapprovedInvoices() => Response(await _approvalService.GetUnapprovedInvoicesAsync(HttpContext)); [HttpPost("{invoiceId:guid}/approve")] public async Task>> Approve(Guid invoiceId) => Response(await _approvalService.ApproveAsync(invoiceId, HttpContext)); [HttpPost("{invoiceId:guid}/change-plan")] public async Task>> ChangePlan(Guid invoiceId, [FromBody] ChangeRenewalPlanRequest request) => Response(await _approvalService.ChangePlanAsync(invoiceId, request.NewCustomerPlanId, HttpContext)); [HttpPost("{invoiceId:guid}/reject")] public async Task>> Reject(Guid invoiceId) => Response(await _approvalService.RejectAsync(invoiceId, HttpContext)); } }