<?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('parent_id')->nullable()->after('id')->constrained('tasks')->onDelete('cascade');
            $table->integer('rating')->nullable()->after('priority');
            $table->string('url')->nullable()->after('description');
            $table->string('email')->nullable()->after('url');
            $table->string('phone')->nullable()->after('email');
            $table->integer('priority_score')->nullable()->after('rating');
            $table->decimal('estimates', 8, 2)->nullable()->after('priority_score');
            $table->timestamp('start_date')->nullable()->after('due_date');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->dropForeign(['parent_id']);
            $table->dropColumn(['parent_id', 'rating', 'url', 'email', 'phone', 'priority_score', 'estimates', 'start_date']);
        });
    }
};
