<?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('assignment_rules', function (Blueprint $table) {
            $table->string('name')->nullable()->after('business_id');
        });

        Schema::create('assignment_failure_queue', function (Blueprint $table) {
            $table->id();
            $table->foreignId('business_id')->index();
            $table->string('module');
            $table->string('assignable_type')->nullable();
            $table->unsignedBigInteger('assignable_id')->nullable();
            $table->text('reason');
            $table->string('status')->default('open')->index();
            $table->foreignId('resolved_by')->nullable();
            $table->timestamp('resolved_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('assignment_failure_queue');
        Schema::table('assignment_rules', function (Blueprint $table) {
            $table->dropColumn('name');
        });
    }
};
