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

        Schema::create('activation_histories', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->index();
            $table->unsignedBigInteger('activation_request_id')->nullable()->index();
            $table->unsignedBigInteger('admin_id')->nullable()->index();
            $table->string('event', 60)->index();
            $table->string('status', 40)->nullable()->index();
            $table->string('verification_channel', 60)->nullable()->index();
            $table->string('source', 100)->nullable()->index();
            $table->string('payment_method', 100)->nullable()->index();
            $table->string('transaction_id', 191)->nullable()->index();
            $table->string('trx_id', 191)->nullable()->index();
            $table->decimal('amount', 12, 2)->default(0);
            $table->text('note')->nullable();
            $table->json('metadata')->nullable();
            $table->timestamp('happened_at')->nullable()->index();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        if (Schema::hasTable('activation_histories')) {
            Schema::drop('activation_histories');
        }
    }
};
