using Lada.Framework.Infrastructures;
using Lada.Framework.Infrastructures.Helpers;
using Ladaer.BackEnd.Infrastructures.DTO.Models.Finance;
using Ladaer.BackEnd.Infrastructures.Services.Report.Finance;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Ladaer.BackEnd.Controllers.Finance
{
    /// <summary>
    /// Controller cho báo cáo thu chi
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class IncomeExpenseReportController : ControllerBase
    {
        private readonly IIncomeExpenseReportService _service;

        /// <summary>
        /// Khởi tạo một thể hiện của <see cref="IncomeExpenseReportController"/>.
        /// </summary>
        /// <param name="service">Service báo cáo thu chi.</param>
        public IncomeExpenseReportController(IIncomeExpenseReportService service)
        {
            _service = service;
        }

        /// <summary>
        /// Lấy báo cáo thu chi theo khoảng thời gian
        /// </summary>
        /// <param name="request">Thông tin khoảng thời gian báo cáo</param>
        /// <returns>Báo cáo thu chi theo ngày</returns>
        [HttpPost("GetReport")]
        [Authorize(Roles = "IncomeExpenseReport.View")]
        public async Task<IActionResult> GetReport([FromBody] IncomeExpenseReportRequest request)
        {
            var currentUser = User.GetCurrentUser();
            var result = await _service.GetIncomeExpenseReportAsync(request, currentUser.UserId);
            return Ok(result);
        }
    }
}

