<?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('topups', function (Blueprint $table) {
            $table->id();
            $table->string('topup_id')->unique();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('payment_method_id')->constrained()->cascadeOnDelete();

            $table->unsignedBigInteger('amount');
            $table->unsignedBigInteger('fee_flat')->default(0);
            $table->decimal('fee_percent', 5, 2)->default(0);
            $table->unsignedBigInteger('total_amount');
            $table->string('status')->default('pending');
            $table->string('payment_ref')->nullable();
            $table->string('proof_image')->nullable();
            $table->text('note')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamp('expired_at')->nullable();

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

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