<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->foreignId('user_id')->nullable()->after('id')->constrained()->onDelete('cascade');
            $table->foreignId('workspace_id')->nullable()->after('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('folder_id')->nullable()->after('workspace_id')->constrained()->onDelete('cascade');
        });
    }

    public function down(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->dropForeign(['user_id']);
            $table->dropForeign(['workspace_id']);
            $table->dropForeign(['folder_id']);
            $table->dropColumn(['user_id', 'workspace_id', 'folder_id']);
        });
    }
};
