<?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('tenant_messaging_configs')) {
            return;
        }

        Schema::table('tenant_messaging_configs', function (Blueprint $table): void {
            if (! Schema::hasColumn('tenant_messaging_configs', 'automation_enabled')) {
                $table->boolean('automation_enabled')->default(true)->after('is_active');
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('tenant_messaging_configs')) {
            return;
        }

        Schema::table('tenant_messaging_configs', function (Blueprint $table): void {
            if (Schema::hasColumn('tenant_messaging_configs', 'automation_enabled')) {
                $table->dropColumn('automation_enabled');
            }
        });
    }
};
