<?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::create('verification_check_acknowledgements', function (Blueprint $table) {
            $table->id();
            $table->foreignId('managed_environment_id')->constrained()->cascadeOnDelete();
            $table->foreignId('workspace_id')->constrained()->cascadeOnDelete();
            $table->foreignId('operation_run_id')->constrained('operation_runs')->cascadeOnDelete();

            $table->string('check_key');
            $table->string('ack_reason', 160);
            $table->timestampTz('expires_at')->nullable();
            $table->timestampTz('acknowledged_at');
            $table->foreignId('acknowledged_by_user_id')->constrained('users');

            $table->timestamps();

            $table->unique(['operation_run_id', 'check_key']);

            $table->index(['managed_environment_id', 'workspace_id', 'operation_run_id']);
            $table->index(['operation_run_id']);
        });
    }

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