<?php

namespace App\Controller;

use App\Entity\AttestationCustom;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class AttestationCustomVerifyController extends AbstractController
{
    #[Route('/attestation/verify/{id}/{hmac}', name: 'app_attestation_custom_verify', requirements: ['id' => '\d+'])]
    public function verify(int $id, string $hmac, EntityManagerInterface $em): Response
    {
        $attestation = $em->getRepository(AttestationCustom::class)->find($id);

        $valid = null !== $attestation && hash_equals($attestation->getHmac(), $hmac);

        return $this->render('attestation_custom/verify.html.twig', [
            'valid' => $valid,
            'attestation' => $valid ? $attestation : null,
        ]);
    }
}
