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

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Api\Model\GetDuplicatesOfRegisteredPersonResponseType;
use Fifa\ConnectId\Sdk\Exception\FifaDuplicateOfRegisteredPersonFoundException;

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

        return null;
    }
}