<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up() {
        Schema::create('workflow_audits', function (Blueprint $table) {
            $table->id();
            $table->string('entity_type'); // Workflow, Step, Transition
            $table->unsignedBigInteger('entity_id');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->string('action'); // created, updated, deleted
            $table->json('before')->nullable();
            $table->json('after')->nullable();
            $table->timestamps();
            $table->index(['entity_type', 'entity_id']);
        });
    }
    public function down() {
        Schema::dropIfExists('workflow_audits');
    }
};
