namespace MyOffice.Web.Controllers;

using AutoMapper;
using Core.Extensions;
using Infrastructure.Attributes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MyOffice.Web.Models.Dashboard;
using Services.Dashboard;

[Authorize]
[DefaultFromBody]
public class DashboardController : BaseApiController
{
	private readonly ILogger<DashboardController> _logger;
	private readonly DashboardService _dashboardService;
	private readonly IMapper _mapper;

	public DashboardController(
		ILogger<DashboardController> logger,
		DashboardService dashboardService,
		IMapper mapper
	)
	{
		_logger = logger;
		_dashboardService = dashboardService;
		_mapper = mapper;
	}


	public ObjectResult Index()
	{
		var data = _dashboardService.GetDashboardRestData(UserId);

		return OkResponse(_mapper.Map<DashboardViewModel>(data));
	}

	public ObjectResult Income(DateTime from, DateTime to, [AsGuid(true)] string? category)
	{
		var data = _dashboardService.GetDashboardIncomeData(UserId, from.StartOfDay(), to.EndOfDay(), category?.AsGuidNull());

		return OkResponse(_mapper.Map<DashboardIncomeDataViewModel>(data));
	}


	public ObjectResult Outcome(DateTime from, DateTime to, [AsGuid(true)] string? category)
	{
		var data = _dashboardService.GetDashboardOutcomeData(UserId, from.StartOfDay(), to.EndOfDay(), category?.AsGuidNull());

		return OkResponse(_mapper.Map<DashboardIncomeDataViewModel>(data));
	}
}
