<?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('role_assignment_audits', function (Blueprint $table) {
            $table->id();
            $table->foreignId('actor_user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('subject_user_id')->constrained('users')->cascadeOnDelete();
            $table->uuid('correlation_id')->index();
            $table->json('previous_roles'); $table->json('new_roles');
            $table->json('added_roles'); $table->json('removed_roles');
            $table->string('result', 32); $table->timestamps();
        });
    }
    public function down(): void { Schema::dropIfExists('role_assignment_audits'); }
};
