<?php
declare(strict_types=1);

namespace Autogedal\EanTools\Model\Spreadsheet;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;

class TempFolder
{
    private ?string $path = null;

    public function __construct(private readonly Filesystem $filesystem)
    {
    }

    public function getPath(): string
    {
        if ($this->path === null) {
            $directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
            $directory->create();
            $this->path = rtrim($directory->getAbsolutePath(), '/\\');
        }

        return $this->path;
    }
}
