<?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('workspaces', function (Blueprint $table): void {
            $table->timestamp('closed_at')->nullable()->after('archived_at');
            $table->foreignId('closed_by_platform_user_id')->nullable()->after('closed_at')->constrained('platform_users')->nullOnDelete();
            $table->text('closed_reason')->nullable()->after('closed_by_platform_user_id');

            $table->index('closed_at');
        });
    }

    public function down(): void
    {
        Schema::table('workspaces', function (Blueprint $table): void {
            $table->dropIndex(['closed_at']);
            $table->dropConstrainedForeignId('closed_by_platform_user_id');
            $table->dropColumn(['closed_at', 'closed_reason']);
        });
    }
};
