<?php

declare(strict_types=1);

namespace App\Services\SystemConfig;

use Symfony\Component\HttpFoundation\File\UploadedFile;

class SettingFileUploader
{
    private const FIXED_PATHS = [
        'app_logo' => 'assets/img/logo.png',
        'app_favicon' => 'assets/img/favicon.png',
        'maintenance_mode_image' => 'assets/img/maintenance.png',
    ];

    public function replace(string $key, UploadedFile $file, mixed $oldValue): ?string
    {
        $dir = public_path('assets/img');

        if (! is_dir($dir)) {
            mkdir($dir, 0755, true);
        }

        if (isset(self::FIXED_PATHS[$key])) {
            $filename = basename(self::FIXED_PATHS[$key]);
            $file->move($dir, $filename);

            return self::FIXED_PATHS[$key];
        }

        return $file->store('uploads/settings', 'public');
    }
}
