<?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('contact_submissions', function (Blueprint $table) {
            $table->foreignId('lead_id')->nullable()->after('status')->constrained('leads')->nullOnDelete();
            $table->timestamp('converted_at')->nullable()->after('lead_id');
            $table->index('lead_id');
        });
    }

    public function down(): void
    {
        Schema::table('contact_submissions', function (Blueprint $table) {
            $table->dropConstrainedForeignId('lead_id');
            $table->dropColumn('converted_at');
        });
    }
};
