<?php

namespace ShopMagicVendor\MailerLite\Exceptions;

use ShopMagicVendor\Psr\Http\Client\RequestExceptionInterface;
use ShopMagicVendor\Psr\Http\Message\RequestInterface;
use ShopMagicVendor\Psr\Http\Message\ResponseInterface;
class MailerLiteHttpException extends MailerLiteException implements RequestExceptionInterface
{
    protected RequestInterface $request;
    protected ResponseInterface $response;
    public function __construct(RequestInterface $request, ResponseInterface $response)
    {
        $message = sprintf('[url] %s [http method] %s [status code] %s [reason phrase] %s', $request->getRequestTarget(), $request->getMethod(), $response->getStatusCode(), $response->getReasonPhrase());
        $this->request = $request;
        $this->response = $response;
        parent::__construct($message, $response->getStatusCode());
    }
    public function getResponse(): ResponseInterface
    {
        return $this->response;
    }
    public function getRequest(): RequestInterface
    {
        return $this->request;
    }
}
