<?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('audit_logs', function (Blueprint $table) {
            $table->uuid('event_uuid')->nullable()->unique()->after('id');
            $table->string('outcome', 20)->default('success')->after('response_status');
            $table->json('result_context')->nullable()->after('metadata');
            $table->string('previous_hash', 64)->nullable()->after('result_context');
            $table->string('integrity_hash', 64)->nullable()->index()->after('previous_hash');
            $table->timestamp('archived_at')->nullable()->index()->after('performed_at');
            $table->boolean('legal_hold')->default(false)->index()->after('archived_at');
        });
    }

    public function down(): void
    {
        Schema::table('audit_logs', fn (Blueprint $table) => $table->dropColumn([
            'event_uuid','outcome','result_context','previous_hash','integrity_hash','archived_at','legal_hold',
        ]));
    }
};
