<?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('dsar_evidence_items', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('solicitor_id')->index();
            $table->foreignId('contact_message_attachment_id')->constrained()->cascadeOnDelete();
            $table->foreignId('dsar_id')->nullable()->constrained()->nullOnDelete();
            $table->unsignedSmallInteger('page')->nullable();
            $table->text('quote')->nullable();
            $table->json('bbox')->nullable();
            $table->string('category', 32);
            $table->string('severity', 16);
            $table->text('comment');
            $table->string('source', 8)->default('ai');
            $table->timestamp('confirmed_at')->nullable();
            $table->timestamp('dismissed_at')->nullable();
            $table->text('human_notes')->nullable();
            $table->timestamps();

            $table->index(['solicitor_id', 'dsar_id'], 'dei_solicitor_dsar_idx');
            $table->index(['contact_message_attachment_id', 'dismissed_at'], 'dei_attachment_dismissed_idx');
        });
    }

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