<?php

namespace App\Exceptions;

use Openguru\OpenCartFramework\Contracts\ExceptionHandlerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Openguru\OpenCartFramework\Telegram\Exceptions\TelegramInvalidSignatureException;
use Psr\Log\LoggerInterface;
use Throwable;

class CustomExceptionHandler implements ExceptionHandlerInterface
{
    public function respond(Throwable $exception): ?JsonResponse
    {
        if ($exception instanceof TelegramInvalidSignatureException) {
            return new JsonResponse([
                'error' => 'Invalid Signature',
                'code' => 'NO_INIT_DATA',
            ], Response::HTTP_BAD_REQUEST);
        }

        return null;
    }
}
