<?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('cms_audit_log', function (Blueprint $table) {
            $table->id();
            $table->string('action', 50)->index();
            $table->unsignedInteger('page_id')->nullable()->index();
            $table->string('page_title')->nullable();
            $table->unsignedInteger('admin_user_id')->nullable()->index();
            // Encrypted at rest via OptionalEncrypted casts on the model
            $table->text('admin_user_name')->nullable();
            $table->text('ip_address')->nullable();
            $table->mediumText('details')->nullable();
            $table->timestamps();

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

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