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

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Api\Model\GetDuplicatesResponseType;
use Fifa\ConnectId\Sdk\Exception\FifaDuplicatedPersonFoundException;

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

        return null;
    }
}