<?php

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

/**
 * Tabel activity_log untuk Spatie Laravel Activitylog.
 * Digunakan sebagai Audit Log aplikasi.
 *
 * - log_name: nama group log (e.g. 'order', 'product', 'auth')
 * - description: deskripsi singkat aktivitas
 * - subject: model yang diubah (polymorphic)
 * - causer: siapa yang melakukan (polymorphic, biasanya User)
 * - properties: JSON perubahan (old_values / new_values / attributes)
 * - batch_uuid: untuk mengelompokkan aktivitas dalam satu transaksi
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('activity_log', function (Blueprint $table) {
            $table->id();
            $table->string('log_name')->nullable()->index();
            $table->text('description');

            $table->nullableMorphs('subject', 'subject');
            $table->nullableMorphs('causer', 'causer');

            $table->json('properties')->nullable();
            $table->uuid('batch_uuid')->nullable();
            $table->string('event')->nullable();

            $table->timestamps();
        });
    }

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