<?php

namespace ReviewX\Apiz\Http\Clients;

use Exception;
use ReviewX\Psr\Http\Message\RequestInterface;
use ReviewX\Psr\Http\Message\ResponseInterface;
use ReviewX\Psr\Http\Message\UriInterface;
abstract class AbstractClient
{
    /**
     * @var array
     */
    protected $config;
    public function __construct($config = [])
    {
        $this->config = $config;
    }
    /**
     * @return string
     */
    protected abstract function getRequestClass() : string;
    /**
     * @return string
     */
    protected abstract function getResponseClass() : string;
    /**
     * @return string
     */
    protected abstract function getUriClass() : string;
    /**
     * @param array $args
     * @return ResponseInterface
     * @throws Exception
     */
    public abstract function send(...$args) : ResponseInterface;
    /**
     * @param mixed ...$args
     * @return RequestInterface
     */
    public function getRequest(...$args)
    {
        $class = $this->getRequestClass();
        return new $class(...$args);
    }
    /**
     * @param mixed ...$args
     * @return ResponseInterface
     */
    public function getResponse(...$args)
    {
        $class = $this->getResponseClass();
        return new $class(...$args);
    }
    /**
     * @param mixed ...$args
     * @return UriInterface
     */
    public function getUri(...$args)
    {
        $class = $this->getUriClass();
        return new $class(...$args);
    }
    /**
     * @param ResponseInterface $response
     * @return bool
     */
    public function isValidResponse(ResponseInterface $response)
    {
        $responseClass = $this->getResponseClass();
        if ($response instanceof $responseClass) {
            return \true;
        }
        return \false;
    }
}
