using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SportsDivision.Application.Interfaces;

namespace SportsDivision.Web.Controllers;

[Authorize]
public class DashboardController : Controller
{
    private readonly IDashboardService _dashboardService;
    private readonly ITournamentService _tournamentService;

    public DashboardController(IDashboardService dashboardService, ITournamentService tournamentService)
    {
        _dashboardService = dashboardService;
        _tournamentService = tournamentService;
    }

    public async Task<IActionResult> Index(int? tournamentId)
    {
        var dashboard = await _dashboardService.GetDashboardAsync(tournamentId);

        var tournaments = await _tournamentService.GetAllAsync(includeArchived: false);
        ViewBag.Tournaments = tournaments;
        ViewBag.SelectedTournamentId = tournamentId;

        return View(dashboard);
    }
}
