<?php

declare(strict_types=1);

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('review_packs', function (Blueprint $table): void {
            $table->foreignId('environment_review_id')
                ->nullable()
                ->after('evidence_snapshot_id')
                ->constrained('environment_reviews')
                ->nullOnDelete();

            $table->index(['environment_review_id', 'generated_at']);
        });
    }

    public function down(): void
    {
        Schema::table('review_packs', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('environment_review_id');
        });
    }
};
