<?php

namespace Database\Seeders;

use App\Models\MediaStorageTarget;
use Illuminate\Database\Seeder;
use Illuminate\Support\Arr;

class MediaStorageTargetSeeder extends Seeder
{
    public function run(): void
    {
        $targets = [
            [
                'key' => 'local-ssd',
                'name' => 'Local SSD (Hot Storage)',
                'driver' => 'local',
                'config' => [
                    'root' => storage_path('app/public'),
                    'visibility' => 'public',
                    'url' => rtrim(config('app.url', env('APP_URL', 'http://localhost')), '/').'/storage',
                    'monitor_path' => storage_path('app/public'),
                ],
                'is_hot' => true,
                'is_default' => true,
                'priority' => 100,
            ],
            [
                'key' => 'hetzner-archive',
                'name' => 'Hetzner Storage Box (Archive)',
                'driver' => 'sftp',
                'config' => [
                    'host' => env('HETZNER_STORAGE_HOST', 'storagebox.example.com'),
                    'username' => env('HETZNER_STORAGE_USERNAME', 'u000000'),
                    'password' => env('HETZNER_STORAGE_PASSWORD'),
                    'port' => (int) env('HETZNER_STORAGE_PORT', 22),
                    'root' => env('HETZNER_STORAGE_ROOT', '/fotospiel'),
                    'timeout' => 30,
                    'monitor_path' => env('HETZNER_STORAGE_MONITOR_PATH', '/mnt/hetzner'),
                ],
                'is_hot' => false,
                'is_default' => false,
                'priority' => 50,
            ],
        ];

        foreach ($targets as $payload) {
            $config = Arr::pull($payload, 'config');

            MediaStorageTarget::updateOrCreate(
                ['key' => $payload['key']],
                array_merge($payload, ['config' => $config])
            );
        }
    }
}
