<?php

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

// Per-customer auto-reply opt-out. Customers on this list always get human
// replies — AutoReplyTicket skips them regardless of the global automation
// settings or confidence threshold. Useful for VIPs, high-touch accounts,
// problem-customers where a stock auto-reply would be the wrong move.
//
// Two identifier types supported:
//   - 'email'        : matches Ticket.customer_email (case-insensitive)
//   - 'whmcs_user'   : matches Ticket.whmcs_user_id (integer)
// Pick whichever the admin has handier; both work the same downstream.
return new class extends Migration {
    public function up(): void
    {
        Schema::create('ticket_reply_blocklist', function (Blueprint $t) {
            $t->id();
            $t->enum('identifier_type', ['email', 'whmcs_user'])->index();
            $t->string('identifier', 255);
            $t->string('label', 128)->nullable()
                ->comment('Optional human-readable label, e.g. "John Smith (VIP)"');
            $t->text('reason')->nullable();
            $t->boolean('enabled')->default(true)->index();
            $t->foreignId('added_by')->nullable()->constrained('users')->nullOnDelete();
            $t->timestamps();
            $t->unique(['identifier_type', 'identifier']);
        });
    }

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