<?php

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

class AddRunLockColumnsToWhatsappCampaignsTable extends Migration
{
    public function up()
    {
        Schema::table('whatsapp_campaigns', function (Blueprint $table) {
            if (!Schema::hasColumn('whatsapp_campaigns', 'run_lock_token')) {
                $table->string('run_lock_token')->nullable();
            }
            if (!Schema::hasColumn('whatsapp_campaigns', 'run_lock_until')) {
                $table->dateTime('run_lock_until')->nullable();
            }
            if (!Schema::hasColumn('whatsapp_campaigns', 'run_lock_user_id')) {
                $table->integer('run_lock_user_id')->nullable();
            }
        });
    }

    public function down()
    {
        // SQLite قد لا يدعم dropColumn بدون doctrine/dbal
        try {
            Schema::table('whatsapp_campaigns', function (Blueprint $table) {
                $table->dropColumn(['run_lock_token','run_lock_until','run_lock_user_id']);
            });
        } catch (\Exception $e) {}
    }
}
