<?php

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

/**
 * Central registry of storage destinations (Local / S3 / Cloudflare R2) that
 * tenants are assigned to. Credentials live in the encrypted `config` payload.
 * This is landlord data — never tenant-scoped.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('storage_sources', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('driver', 20); // local|s3|r2
            $table->text('config')->nullable(); // encrypted JSON: bucket, region, key, secret, endpoint, url, ...
            $table->unsignedBigInteger('quota_bytes')->nullable(); // null = unlimited
            $table->boolean('is_default')->default(false);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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