<?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
    {
        if (Schema::hasTable('lead_followups')) {
            return;
        }

        Schema::create('lead_followups', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('lead_id');
            $table->timestamp('followup_at');
            $table->string('status', 20)->default('pending');
            $table->string('channel', 20)->default('call');
            $table->string('outcome', 50)->nullable();
            $table->timestamp('meeting_at')->nullable();
            $table->string('meeting_mode', 30)->nullable();
            $table->text('message')->nullable();
            $table->text('notes')->nullable();
            $table->timestamp('reminder_sent_at')->nullable();
            $table->timestamp('completed_at')->nullable();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->timestamps();

            $table->index(['status', 'followup_at']);
            $table->index('lead_id');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('lead_followups');
    }
};
