<?php

declare(strict_types=1);

namespace App\Tests\Unit\Scolarite\Infrastructure\Storage;

use App\Scolarite\Application\Port\FileStorage;

use function is_string;

use Override;

final class InMemoryFileStorage implements FileStorage
{
    /** @var array<string, string> */
    private array $files = [];

    #[Override]
    public function upload(string $path, mixed $content, string $mimeType): string
    {
        $this->files[$path] = is_string($content) ? $content : '';

        return $path;
    }

    #[Override]
    public function delete(string $path): void
    {
        unset($this->files[$path]);
    }

    public function has(string $path): bool
    {
        return isset($this->files[$path]);
    }

    public function get(string $path): ?string
    {
        return $this->files[$path] ?? null;
    }
}
