<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * The single, platform-wide storage configuration.
 *
 * Replaces the multi-source `storage_sources` registry: there is now exactly
 * one Cloudflare R2 bucket behind every tenant, so the config is a singleton
 * row rather than a table of destinations tenants are assigned to.
 *
 * `storage_sources`, `storage_migrations` and `tenants.storage_source_id` are
 * deliberately left in place — dropping them is irreversible on a live database
 * and nothing reads them anymore.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('storage_settings', function (Blueprint $table) {
            $table->id();

            // Credentials, encrypted as one payload (see StorageSetting::casts).
            // Nullable throughout: an empty row is the valid "not configured in
            // the UI, fall back to .env" state.
            $table->text('config')->nullable();

            // Platform-wide cap across every tenant. Null = unlimited.
            $table->unsignedBigInteger('quota_bytes')->nullable();

            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('storage_settings');
    }
};
