using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ROLAC.API.DTOs.Expense;
using ROLAC.API.Services.Ai;

namespace ROLAC.API.Controllers;

[ApiController]
[Route("api/expense-ai")]
[Authorize]   // Open to any authenticated user — same audience as the expense-entry form, which any
              // member filing a reimbursement can reach. The endpoint only reads the category catalog.
public class ExpenseAiController : ControllerBase
{
    private readonly IExpenseAiService _svc;
    public ExpenseAiController(IExpenseAiService svc) => _svc = svc;

    [HttpPost("assist")]
    public async Task<IActionResult> Assist([FromBody] ExpenseAiAssistRequest request, CancellationToken ct)
    {
        if (string.IsNullOrWhiteSpace(request.Text))
            return BadRequest("Text is required.");

        var suggestion = await _svc.SuggestAsync(request.Text, request.Amount, ct);
        return Ok(suggestion);
    }
}
