<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Controller\Site;

use CpCreation\VitiCore\Gite\Model\Gite;
use CpCreation\VitiCore\Gite\Model\Room;
use CpCreation\VitiCore\Gite\Repository\GiteRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\ValueResolver;

final class CottageController extends AbstractController
{
    public function __construct(
        private readonly GiteRepository $cottageRepository,
        private readonly EntityManagerInterface $entityManager,
    ) {
    }

    public function index(
        #[ValueResolver('translation_resolver')]
        Gite $gite,
    ): Response {
        return $this->render('cottage.html.twig', [
            'classMenu' => 'black',
            'cottage' => $gite,
        ]);
    }

    public function item(
        #[ValueResolver('translation_resolver')]
        Room $room,
    ): Response {
        $cottages = $this->entityManager->getRepository(Gite::class)->findAll();

        $prevRoom = $this->cottageRepository->findOneBy(['position' => $room->getPosition() - 1]);
        $nextRoom = $this->cottageRepository->findOneBy(['position' => $room->getPosition() + 1]);

        return $this->render('cottageItem.html.twig', [
            'cottages' => $cottages,
            'room' => $room,
            'prevItem' => $prevRoom,
            'nextItem' => $nextRoom,
        ]);
    }
}
