<?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::create('ai_staff_department_rules', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('ai_staff_profile_id');
            $table->unsignedBigInteger('department_id');
            $table->boolean('enabled')->default(true);
            $table->enum('mode', ['autonomous', 'draft', 'disabled'])->default('draft');
            $table->json('priority_overrides')->nullable();
            $table->json('excluded_topics')->nullable();
            $table->timestamps();

            $table->foreign('ai_staff_profile_id')->references('id')->on('ai_staff_profiles')->onDelete('cascade');
            $table->foreign('department_id')->references('id')->on('ticket_departments')->onDelete('cascade');
            $table->unique(['ai_staff_profile_id', 'department_id'], 'ai_dept_rule_unique');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('ai_staff_department_rules');
    }
};
