<?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('activity_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->nullable()->constrained()->onDelete('set null');
            $table->string('action')->nullable(); // login, logout, draft, submit, create, update, delete
            $table->text('description'); // Full description like "User (Admin) Login"
            $table->string('module')->nullable(); // Login, Logout, Invoice, Daily Distribution, Role, User, etc.
            $table->timestamps(); // created_at and updated_at

            $table->index(['user_id', 'created_at']);
            $table->index('action');
            $table->index('module');
        });
    }

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