<?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('pakasir_settings', function (Blueprint $table) {
            $table->id();
            $table->string('slug')->nullable();
            $table->string('api_key')->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->boolean('broadcast_enabled')->default(true);
            $table->string('broadcast_message')->nullable();
            $table->integer('broadcast_channel')->default(9);
            $table->timestamps();
        });

        Schema::create('pakasir_transactions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->string('character_id')->nullable();
            $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('streamer_code')->nullable();
            $table->string('status')->default('pending');
            $table->text('payment_url')->nullable();
            $table->json('response_data')->nullable();
            $table->timestamp('expired_at')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();

            $table->index('user_id');
            $table->index('status');
            $table->index('reference_id');
            $table->index('transaction_id');
        });
    }

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