using AccountTracking.Api.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AccountTracking.Api.Controllers;

[ApiController]
[Route("api/dashboard")]
[Authorize]
public class DashboardController : ControllerBase
{
    private readonly DashboardService _svc;
    public DashboardController(DashboardService svc) => _svc = svc;

    [HttpGet("summary")]
    public async Task<IActionResult> Summary([FromQuery] int year, [FromQuery] int? month)
        => Ok(await _svc.GetSummaryAsync(year, month));

    [HttpGet("spending-by-category")]
    public async Task<IActionResult> SpendingByCategory([FromQuery] int year, [FromQuery] int? month)
        => Ok(await _svc.GetSpendingByCategoryAsync(year, month));

    [HttpGet("monthly-balances")]
    public async Task<IActionResult> MonthlyBalances([FromQuery] int year)
        => Ok(await _svc.GetMonthlyBalancesAsync(year));

    [HttpGet("cumulative-spending")]
    public async Task<IActionResult> CumulativeSpending([FromQuery] int year, [FromQuery] int month)
        => Ok(await _svc.GetCumulativeSpendingAsync(year, month));
}
