<?php

namespace Worldline\Vendor\OnlinePayments\Sdk\Communication;

/**
 * Class ResponseClassMap
 *
 * @package OnlinePayments\Sdk\Communication
 */
class ResponseClassMap
{
    /** @var string */
    public string $defaultSuccessResponseClassName = '';
    /** @var string */
    public string $defaultErrorResponseClassName = '';
    /** @var string[]  */
    private array $responseClassNamesByHttpStatusCode = array();
    /**
     * @param int $httpStatusCode
     * @param string $responseClassName
     * @return $this
     */
    public function addResponseClassName(int $httpStatusCode, string $responseClassName) : ResponseClassMap
    {
        $this->responseClassNamesByHttpStatusCode[$httpStatusCode] = $responseClassName;
        return $this;
    }
    /**
     * @param int $httpStatusCode
     * @return string
     */
    public function getResponseClassName(int $httpStatusCode) : string
    {
        if (\array_key_exists($httpStatusCode, $this->responseClassNamesByHttpStatusCode)) {
            return $this->responseClassNamesByHttpStatusCode[$httpStatusCode];
        }
        if ($httpStatusCode < 400) {
            return $this->defaultSuccessResponseClassName;
        }
        return $this->defaultErrorResponseClassName;
    }
}
