<?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('dsar_evidence_items', function (Blueprint $table) {
            // Which care setting (placement) this highlight relates to. Item-level because
            // a single document can contain evidence spanning several care settings.
            $table->foreignId('care_setting_id')
                ->nullable()
                ->after('dsar_id')
                ->constrained('care_settings')
                ->nullOnDelete();

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

            $table->index(['care_setting_id', 'care_setting_is_suggested'], 'dei_care_setting_idx');
        });
    }

    public function down(): void
    {
        Schema::table('dsar_evidence_items', function (Blueprint $table) {
            $table->dropIndex('dei_care_setting_idx');
            $table->dropForeign(['care_setting_id']);
            $table->dropColumn(['care_setting_id', 'care_setting_is_suggested']);
        });
    }
};
