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

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Api\Model\GetFacilityDuplicatesResponseType;
use Fifa\ConnectId\Sdk\Exception\FifaDuplicatedFacilityFoundException;

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

        return null;
    }
}