<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CmsBundle\Controller\Fragment;

use Contao\CoreBundle\Controller\AbstractFragmentController;
use Ferienpass\CoreBundle\Entity\Attendance;
use Ferienpass\CoreBundle\Repository\AttendanceRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Confirmation page shown after an anonymous applicant clicks the e-mail link.
 * Public (the visitor is not logged in); it only echoes the offer name + status.
 */
class ApplicationConfirmedController extends AbstractFragmentController
{
    public function __construct(private readonly AttendanceRepository $attendances)
    {
    }

    public function __invoke(Request $request): Response
    {
        $attendance = $this->attendances->findOneBy(['uuid' => (string) $request->attributes->get('attendance')]);

        return $this->render('@Contao/fragment/application_confirmed.html.twig', [
            'attendance' => $attendance instanceof Attendance ? $attendance : null,
        ]);
    }
}
