<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create("audit_trails", function (Blueprint $table) {
            $table->id();
            $table->string("module_type");
            $table->string("module_name");
            $table->integer("module_id")->nullable();
            $table->string("action");
            $table->string("action_by")->nullable();
            $table->string("action_by_name")->index();
            $table->text("log_info");
            $table->json("previous_data")->nullable();
            $table->json("new_data")->nullable();
            $table->string("ip_address")->nullable();
            $table->string("user_agent")->nullable();
            $table->timestamps();

            $table->index(["module_type", "module_name", "action"]);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists("audit_trails");
    }
};
