<?php

namespace Fifa\ConnectId\Sdk\ExceptionHandler\Handler;

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Api\Model\GetOrganisationDuplicatesResponseType;
use Fifa\ConnectId\Sdk\Exception\FifaDuplicatedOrganisationFoundException;

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

        return null;
    }
}