<?php

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

/**
 * Exhibits are keyed per confirmed finding, not per document page: two findings
 * on the same page are each independently exhibitable. Swap the (document, page)
 * unique for a (statement, evidence item) unique.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('witness_statement_exhibits', function (Blueprint $table) {
            $table->dropUnique('wse_unique_page');
            $table->unique(['witness_statement_id', 'dsar_evidence_item_id'], 'wse_unique_item');
        });
    }

    public function down(): void
    {
        Schema::table('witness_statement_exhibits', function (Blueprint $table) {
            $table->dropUnique('wse_unique_item');
            $table->unique(['witness_statement_id', 'document_id', 'page'], 'wse_unique_page');
        });
    }
};
