<?php

namespace App\Framework\HttpClient;

final readonly class DefaultHttpClient implements HttpClient
{
    public function __construct(
        private HttpClient        $client = new HttpClientWithMiddleware(new CurlHttpClient()),
        private RequestValidator  $requestValidator = new RequestValidator(),
        private ResponseValidator $responseValidator = new ResponseValidator(),
    ){}

    public function send(ClientRequest $request): ClientResponse
    {
        $this->requestValidator->validate($request);

        $response = $this->client->send($request);

        $this->responseValidator->validate($response, $request->options);

        return $response;
    }
}
