<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('call_queues', function (Blueprint $table) {
            $table->id();

            $table->foreignId('solicitor_id')->constrained()->cascadeOnDelete();

            $table->string('name');
            $table->string('type', 50)->index();
            $table->unsignedInteger('priority')->default(100);

            $table->boolean('is_active')->default(true)->index();
            $table->unsignedInteger('max_wait_seconds')->nullable();
            $table->unsignedInteger('max_ring_seconds')->nullable();

            $table->foreignId('voicemail_user_id')->nullable()->constrained('users')->nullOnDelete();

            $table->json('meta')->nullable();

            $table->timestamps();

            $table->unique(['solicitor_id', 'type']);
            $table->index(['solicitor_id', 'is_active']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('call_queues');
    }
};
