<?php

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

/**
 * Capture a WhatsApp number for the client funnel. The lead's WhatsApp number
 * may differ from the contact phone (the client can opt to use a different
 * number); notifications route the WhatsApp channel to it.
 */
return new class extends Migration {
    public function up(): void
    {
        Schema::table('bms_leads', function (Blueprint $t) {
            if (! Schema::hasColumn('bms_leads', 'whatsapp')) {
                $t->string('whatsapp', 30)->nullable()->after('contact_id');
            }
        });
        Schema::table('bms_wizard_sessions', function (Blueprint $t) {
            if (! Schema::hasColumn('bms_wizard_sessions', 'contact_whatsapp')) {
                $t->string('contact_whatsapp', 30)->nullable()->after('contact_phone');
            }
        });
    }

    public function down(): void
    {
        Schema::table('bms_leads', fn (Blueprint $t) => $t->dropColumn('whatsapp'));
        Schema::table('bms_wizard_sessions', fn (Blueprint $t) => $t->dropColumn('contact_whatsapp'));
    }
};
