<?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('leads')) {
            return;
        }

        Schema::create('leads', function (Blueprint $table) {
            $table->id();
            $table->string('company_name');
            $table->string('contact_person_name');
            $table->string('mobile', 20);
            $table->string('email')->nullable();
            $table->unsignedInteger('employee_count');
            $table->string('source', 50)->default('register_free_trial');
            $table->string('status', 30)->default('new');
            $table->timestamp('otp_verified_at')->nullable();
            $table->timestamp('next_followup_at')->nullable();
            $table->timestamp('meeting_at')->nullable();
            $table->string('meeting_mode', 30)->nullable();
            $table->timestamp('last_contacted_at')->nullable();
            $table->text('notes')->nullable();
            $table->unsignedBigInteger('assigned_to')->nullable();
            $table->timestamps();

            $table->index(['status', 'next_followup_at']);
            $table->index(['mobile', 'status']);
            $table->index('assigned_to');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('leads');
    }
};
