<?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('documents', function (Blueprint $table) {
            // The source institution this uploaded document came from (provenance), used for grouping.
            // DSAR email attachments inherit their source from the DSAR's institution instead.
            $table->foreignId('institution_id')
                ->nullable()
                ->after('type_id')
                ->constrained('institutions')
                ->nullOnDelete();

            // True while the source is an unconfirmed AI suggestion; cleared when a human accepts/overrides.
            $table->boolean('institution_is_suggested')->default(false)->after('institution_id');

            // Human "not evidence" flag — hides the file from the productive review list.
            $table->boolean('evidence_excluded')->default(false)->after('evidence_status');
        });
    }

    public function down(): void
    {
        Schema::table('documents', function (Blueprint $table) {
            $table->dropForeign(['institution_id']);
            $table->dropColumn(['institution_id', 'institution_is_suggested', 'evidence_excluded']);
        });
    }
};
