<?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('users', function (Blueprint $table) {
            $table->string('team_name')->nullable()->after('parent_user_id');
            $table->unsignedBigInteger('reporting_manager_id')->nullable()->after('team_name');
        });

        Schema::table('deals', function (Blueprint $table) {
            $table->string('closure_approval_status')->nullable()->after('status');
            $table->unsignedBigInteger('requested_closure_stage_id')->nullable()->after('closure_approval_status');
            $table->unsignedBigInteger('closure_requested_by')->nullable()->after('requested_closure_stage_id');
            $table->timestamp('closure_requested_at')->nullable()->after('closure_requested_by');
            $table->unsignedBigInteger('closure_approved_by')->nullable()->after('closure_requested_at');
            $table->timestamp('closure_approved_at')->nullable()->after('closure_approved_by');
            $table->text('closure_approval_note')->nullable()->after('closure_approved_at');
        });
    }

    public function down(): void
    {
        Schema::table('deals', fn (Blueprint $table) => $table->dropColumn([
            'closure_approval_status', 'requested_closure_stage_id', 'closure_requested_by',
            'closure_requested_at', 'closure_approved_by', 'closure_approved_at',
            'closure_approval_note',
        ]));
        Schema::table('users', fn (Blueprint $table) => $table->dropColumn([
            'team_name', 'reporting_manager_id',
        ]));
    }
};
