<?php

namespace AutoAdmin\Bundle\Content\Service;

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 GdaApiService
{
    private const GDA_SITE_URL = 'https://gda-site.wsl/';

    private HttpClientInterface $httpClient;

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

    /**
     * @throws TransportExceptionInterface
     * @throws ServerExceptionInterface
     * @throws RedirectionExceptionInterface
     * @throws DecodingExceptionInterface
     * @throws ClientExceptionInterface
     */
    public function getLastActu(string $lang): array
    {
        $response = $this->httpClient->request(
            'GET', self::GDA_SITE_URL.'api/last-actu?lang='.$lang,
            ['verify_peer' => false, 'verify_host' => false]
        );
        $actus = $response->toArray();
        return $actus;
    }
}
