using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ROLAC.API.Authorization;
using ROLAC.API.Services;

namespace ROLAC.API.Controllers;

[ApiController]
[Route("api/finance-dashboard")]
[HasPermission(Modules.FinanceDashboard, PermissionActions.Read)]
public class FinanceDashboardController : ControllerBase
{
    private readonly IFinanceDashboardService _svc;
    public FinanceDashboardController(IFinanceDashboardService svc) => _svc = svc;

    [HttpGet("summary")]
    public async Task<IActionResult> Summary()
        => Ok(await _svc.GetSummaryAsync());

    [HttpGet("income-expense")]
    public async Task<IActionResult> IncomeExpense([FromQuery] DateOnly? from, [FromQuery] DateOnly? to)
        => Ok(await _svc.GetIncomeExpenseAsync(from, to));

    [HttpGet("expense-breakdown")]
    public async Task<IActionResult> ExpenseBreakdown(
        [FromQuery] DateOnly? from, [FromQuery] DateOnly? to,
        [FromQuery] int? ministryId, [FromQuery] int? categoryGroupId)
        => Ok(await _svc.GetExpenseBreakdownAsync(from, to, ministryId, categoryGroupId));
}
