<?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
    {
        // Append-only log: created_at only, no updated_at.
        Schema::create('provisioning_step_events', function (Blueprint $table) {
            $table->id();
            $table->foreignId('run_id')->constrained('provisioning_runs')->cascadeOnDelete();
            $table->string('step');
            $table->unsignedInteger('attempt')->default(0);
            $table->string('outcome');                    // advanced | retry | failed | info
            $table->text('message')->nullable();
            $table->string('external_ref')->nullable();
            $table->timestamp('created_at')->nullable();

            $table->index('run_id');
        });
    }

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