<?php
declare(strict_types=1);

namespace App\Service\File\Storage;

use App\Entity\Core\File;
use App\Service\ApiLegacy\ApiLegacyRequestService;
use App\Service\Utils\UrlBuilder;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
 * Read and write files into the Opentalent API v1 storage
 */
class ApiLegacyStorage implements FileStorageInterface
{
    public function __construct(private ApiLegacyRequestService $apiLegacyRequestService)
    {}

    /**
     * Reads the given file and returns its content as a string
     *
     * @param File $file
     * @return string
     */
    public function read(File $file): string
    {
        $url = '_internal/secure/files/' . $file->getId();
        return $this->apiLegacyRequestService->getContent($url);
    }
}
