<?php

namespace App\Security;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;

/**
 * Gestionnaire d'accès refusé personnalisé pour l'API
 * Retourne des réponses JSON au lieu de rediriger
 */
class ApiAccessDeniedHandler implements AccessDeniedHandlerInterface
{
    public function handle(Request $request, AccessDeniedException $accessDeniedException): JsonResponse
    {
        return new JsonResponse(
            [
                'error' => 'Forbidden',
                'message' => 'You do not have permission to access this resource',
            ],
            403 // HTTP 403 Forbidden
        );
    }
}

