<?php

namespace App\Controller;

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

class AttestationController extends AbstractController
{
    #[Route('/attestation/check/{stripePayoutId}', name: 'app_attestation_check')]
    public function check(string $stripePayoutId, EntityManagerInterface $em): Response
    {
        $payout = $em->getRepository(Payout::class)->findOneBy(['stripePayoutId' => $stripePayoutId]);

        $breadcrumbs = [
            ['name' => 'Accueil', 'url' => '/'],
            ['name' => 'Verification attestation', 'url' => '/attestation/check/'.$stripePayoutId],
        ];

        if (!$payout) {
            return $this->render('attestation/not_found.html.twig', [
                'breadcrumbs' => $breadcrumbs,
            ]);
        }

        return $this->render('attestation/check.html.twig', [
            'payout' => $payout,
            'breadcrumbs' => $breadcrumbs,
        ]);
    }
}
