<?php declare(strict_types=1);

namespace App\Controller;

use App\Repository\UserRepository;
use App\Service\ConfigGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ConfigController extends AbstractController
{
    public function __construct(
        private readonly ConfigGenerator $configGenerator,
        private readonly UserRepository  $userRepository
    ) {
    }

    #[Route('/download-config', name: 'app_config')]
    public function index(): Response
    {
        $user = $this->userRepository->findOneBy(['username' => $this->getUser()->getUserIdentifier()]);

        return $this->configGenerator->generateConfig($user);
    }
}
