<?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('promotion_audit_log')) {
            return;
        }

        Schema::create('promotion_audit_log', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('promotion_id')->nullable()->index();
            $table->unsignedInteger('student_id')->nullable()->index();
            $table->unsignedInteger('user_id')->nullable()->comment('Actor that performed the action');
            $table->string('action_type', 60);
            $table->string('field', 60)->nullable();
            $table->string('old_value', 191)->nullable();
            $table->string('new_value', 191)->nullable();
            $table->text('notes')->nullable();
            $table->timestamp('performed_at')->useCurrent();
            $table->timestamps();
        });
    }

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