<?php

namespace App\Controller;

use App\Download\Framework\Repository\DownloadRepository;
use App\Monitor\Action\Command\MonitorTvShowCommand;
use App\Monitor\Action\Handler\MonitorTvShowHandler;
use App\Tmdb\Tmdb;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

final class IndexController extends AbstractController
{
    public function __construct(
        private readonly Tmdb $tmdb,
        private readonly MonitorTvShowHandler $monitorTvShowHandler,
    ) {}

    #[Route('/', name: 'app_index')]
    public function index(Request $request): Response
    {
        return $this->render('index/index.html.twig', [
            'active_downloads' => $this->getUser()->getActiveDownloads(),
            'recent_downloads' => $this->getUser()->getDownloads(),
            'popular_movies' => $this->tmdb->popularMovies(1, 6),
            'popular_tvshows' => $this->tmdb->popularTvShows(1, 6),
        ]);
    }

    #[Route('/test', name: 'app_test')]
    public function test()
    {
        $result = $this->monitorTvShowHandler->handle(new MonitorTvShowCommand(355));
        return $this->json($result);
    }
}
