<?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
    {
        Schema::table('conversations', function (Blueprint $table) {
            $table->uuid('channel_account_id')->nullable()->after('contact_id');
            $table->foreign('channel_account_id')->references('id')->on('channel_accounts')->nullOnDelete();
            $table->index(['tenant_id', 'channel_account_id']);
        });
    }

    public function down(): void
    {
        Schema::table('conversations', function (Blueprint $table) {
            $table->dropForeign(['channel_account_id']);
            $table->dropIndex(['tenant_id', 'channel_account_id']);
            $table->dropColumn('channel_account_id');
        });
    }
};
