<?php

declare(strict_types=1);

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('dashboard_preferences')) {
            return;
        }

        Schema::table('dashboard_preferences', function (Blueprint $table): void {
            if (! Schema::hasColumn('dashboard_preferences', 'studio_preferences')) {
                $table->json('studio_preferences')->nullable()->after('pinned_spaces');
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('dashboard_preferences')) {
            return;
        }

        Schema::table('dashboard_preferences', function (Blueprint $table): void {
            if (Schema::hasColumn('dashboard_preferences', 'studio_preferences')) {
                $table->dropColumn('studio_preferences');
            }
        });
    }
};