<?php

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

/**
 * Item #2 — flag whether a contact's mobile number is WhatsApp-reachable.
 *
 *  clc_has_whatsapp = NULL  unknown (default)
 *                    1     yes
 *                    0     no
 *
 *  Indicator appears next to every mobile-number display + a toggle
 *  lives on the owner profile. Used by reminder dispatchers to choose
 *  between WA push and SMS fallback.
 *
 *  Named with the clc_ prefix because the contacts table is shared with
 *  the core ERP - this keeps the ClinicCore column isolated so any future
 *  ERP upgrade doesn't reclaim a "has_whatsapp" name we've taken.
 */
class ClcAddHasWhatsappToContacts extends Migration
{
    public function up()
    {
        if (Schema::hasTable('contacts') && !Schema::hasColumn('contacts', 'clc_has_whatsapp')) {
            Schema::table('contacts', function (Blueprint $table) {
                $table->boolean('clc_has_whatsapp')->nullable()->index();
            });
        }
    }

    public function down()
    {
        if (Schema::hasColumn('contacts', 'clc_has_whatsapp')) {
            Schema::table('contacts', function (Blueprint $table) {
                $table->dropColumn('clc_has_whatsapp');
            });
        }
    }
}
