<?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('tripay_settings', function (Blueprint $table) {
            $table->id();
            $table->string('api_key')->nullable();
            $table->string('private_key')->nullable();
            $table->string('merchant_code')->nullable();
            $table->string('payment_method')->nullable()->default('BRIVA');
            $table->boolean('production_mode')->default(false);
            $table->string('return_url')->nullable();
            $table->string('callback_url')->nullable();
            $table->integer('gold_rate')->default(1000);
            $table->integer('min_amount')->default(10000);
            $table->integer('max_amount')->default(10000000);
            $table->boolean('is_active')->default(false);
            $table->timestamps();
        });

        Schema::create('tripay_transactions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->string('reference')->unique();
            $table->string('merchant_ref')->unique();
            $table->integer('amount');
            $table->integer('gold_amount');
            $table->string('payment_method')->nullable();
            $table->string('status')->default('pending');
            $table->text('payment_url')->nullable();
            $table->text('checkout_url')->nullable();
            $table->json('response_data')->nullable();
            $table->timestamp('expired_at')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

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