<?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
    {
        if (Schema::hasTable('admin_activity_logs')) {
            return;
        }

        Schema::create('admin_activity_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('admin_id')->nullable()->index();
            $table->string('admin_name')->nullable();
            $table->string('admin_email')->nullable()->index();
            $table->string('method', 10)->nullable()->index();
            $table->string('route_name')->nullable()->index();
            $table->string('path')->nullable()->index();
            $table->text('full_url')->nullable();
            $table->string('activity_summary')->nullable()->index();
            $table->unsignedSmallInteger('response_status')->nullable()->index();
            $table->string('ip_address', 45)->nullable();
            $table->text('user_agent')->nullable();
            $table->json('query_payload')->nullable();
            $table->json('request_payload')->nullable();
            $table->timestamps();

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

    public function down(): void
    {
        if (!Schema::hasTable('admin_activity_logs')) {
            return;
        }

        Schema::drop('admin_activity_logs');
    }
};
