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

use Fifa\ConnectId\Sdk\Api\ApiException;
use Fifa\ConnectId\Sdk\Api\Model\OrganisationLocalType;
use Fifa\ConnectId\Sdk\Exception\FifaConnectIdException;
use Fifa\ConnectId\Sdk\Exception\FifaOrganisationMergedException;
use Fifa\ConnectId\Sdk\ExceptionHandler\Handler\HandlerInterface;

/**
 * Class FifaOrganisationMergedHandler
 * @package Fifa\ConnectId\Sdk\ExceptionHandler\Handler
 */
class FifaOrganisationMergedHandler extends MergeOperation implements HandlerInterface
{
    const MESSAGE_PATTERN = 'The service responded with a status code %d. The requested organisation was merged with %s.';

    /**
     * Handler method for ApiExceptions
     *
     * @param ApiException $e
     * @return FifaConnectIdException|null
     */
    public function handle(ApiException $e): ?FifaConnectIdException
    {
        return $this->handleInternal($e, OrganisationLocalType::class, FifaOrganisationMergedException::class);
    }

    /**
     * Returns string pattern for message that will be filled with exception code and FIFA ID
     *
     * @return string
     */
    protected function getMessagePattern(): string
    {
        return self::MESSAGE_PATTERN;
    }
}