<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('media', function (Blueprint $table) {
            $table->string('name')->nullable()->after('id');
            $table->string('disk')->default('public')->after('file_path');
            $table->string('mime_type')->nullable()->after('type');
            $table->string('extension', 20)->nullable()->after('mime_type');
            $table->unsignedBigInteger('size')->nullable()->after('extension');
            $table->unsignedInteger('width')->nullable()->after('size');
            $table->unsignedInteger('height')->nullable()->after('width');
            $table->string('category')->nullable()->after('height');
            $table->boolean('is_system')->default(false)->after('category');
            $table->foreignId('uploaded_by')->nullable()->after('is_system')->constrained('users')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('media', function (Blueprint $table) {
            $table->dropConstrainedForeignId('uploaded_by');
            $table->dropColumn([
                'name',
                'disk',
                'mime_type',
                'extension',
                'size',
                'width',
                'height',
                'category',
                'is_system',
            ]);
        });
    }
};
