<?php

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

class AddLeadAssignmentColumns extends Migration
{
    public function up()
    {
        Schema::table('leads', function (Blueprint $table) {
            $table->unsignedBigInteger('assigned_to_user_id')->nullable()->after('lead_status');
            $table->unsignedBigInteger('assigned_by_user_id')->nullable()->after('assigned_to_user_id');
            $table->timestamp('assigned_at')->nullable()->after('assigned_by_user_id');

            $table->foreign('assigned_to_user_id')->references('id')->on('users')->nullOnDelete();
            $table->foreign('assigned_by_user_id')->references('id')->on('users')->nullOnDelete();
        });
    }

    public function down()
    {
        Schema::table('leads', function (Blueprint $table) {
            $table->dropForeign(['assigned_to_user_id']);
            $table->dropForeign(['assigned_by_user_id']);
            $table->dropColumn(['assigned_to_user_id', 'assigned_by_user_id', 'assigned_at']);
        });
    }
}
