<?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('ipaymu_settings', function (Blueprint $table) {
            $table->id();
            $table->string('api_key')->nullable();
            $table->string('va_number')->nullable();
            $table->boolean('production_mode')->default(false);
            $table->string('return_url')->nullable();
            $table->string('notify_url')->nullable();
            $table->string('cancel_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('ipaymu_transactions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->string('transaction_id')->nullable();
            $table->string('reference_id')->unique();
            $table->integer('amount');
            $table->integer('gold_amount');
            $table->string('payment_method')->nullable();
            $table->string('payment_channel')->nullable();
            $table->string('status')->default('pending');
            $table->text('payment_url')->nullable();
            $table->text('va_number')->nullable();
            $table->json('response_data')->nullable();
            $table->timestamp('expired_at')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

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