<?php
namespace Fifa\ConnectId\Sdk\ExceptionHandler\Handler;

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Api\Model\BadRequestResponseType;
use Fifa\ConnectId\Sdk\Exception\InvalidClientDataException;

/**
 * Class InvalidClientDataHandler
 * @package Fifa\ConnectId\Sdk\ExceptionHandler\Handler
 */
class InvalidClientDataHandler implements HandlerInterface
{
    /**
     * Handler method for InvalidClientDataException
     *
     * @param ApiException $e
     * @return InvalidClientDataException|null
     */
    public function handle(ApiException $e): ?InvalidClientDataException
    {
        if ($e->getCode() == 400 && $e->getResponseObject() instanceof BadRequestResponseType) {
            return new InvalidClientDataException($e, $e->getResponseObject());
        }
        
        return null;
    }
}