<?php

declare(strict_types=1);

namespace App\Services\Install;

use Illuminate\Support\Facades\File;

/**
 * 清理 Web 安装向导在 storage/framework/dberp-install 下的临时文件。
 */
final class WebInstallArtifactDirectoryCleaner
{
    public function __construct(
        private readonly ?string $baseDirectory = null,
    ) {}

    public function baseDirectory(): string
    {
        return $this->baseDirectory ?? storage_path('framework/dberp-install');
    }

    public function reset(): void
    {
        $directory = $this->baseDirectory();

        if (! is_dir($directory)) {
            return;
        }

        File::deleteDirectory($directory);
    }
}
