<?php

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

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::connection('mai4')->create('ttrx', function (Blueprint $table) {
            $table->id();
            $table->string('nouid');
            $table->string('order_id')->unique();
            $table->decimal('amount', 15, 2);
            $table->unsignedBigInteger('bank_id')->nullable();
            $table->unsignedBigInteger('pt_id')->nullable();
            $table->string('phone')->nullable();
            $table->string('va_number')->nullable();
            $table->string('status')->default('pending'); // pending, success, failed, canceled
            $table->string('type'); // payment, topup, withdraw, etc
            $table->json('spr_id')->nullable();
            $table->json('jen1')->nullable();
            $table->text('note')->nullable();
            $table->json('pay_data')->nullable(); // Snap response data
            $table->text('failure_message')->nullable();
            $table->timestamp('expiry_time')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->unsignedBigInteger('created_by')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::connection('mai4')->dropIfExists('ttrx');
    }
};
