<?php

namespace App\Services;

use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class HttpClientService
{
    private HttpClientInterface $client;

    public function __construct(HttpClientInterface $client)
    {
        $this->client = $client;
    }

    /**
     * @throws RedirectionExceptionInterface
     * @throws ClientExceptionInterface
     * @throws TransportExceptionInterface
     * @throws ServerExceptionInterface
     */
    public function getStatus(string $method, string $url, array $params=[]): int
    {
        $response = $this->client->request(
            $method,
            $url,
            $params
        );

//        $contentType = $response->getHeaders()['content-type'][0];
        // $contentType = 'application/json'
//        $content = $response->getContent();
        // $content = '{"id":521583, "name":"symfony-docs", ...}'
        //$response->toArray();
        // $content = ['id' => 521583, 'name' => 'symfony-docs', ...]
        return $response->getStatusCode();
        // $statusCode = 200
    }
}
