<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('play_config_versions', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('version_no');
            $table->string('status', 16);
            $table->timestamp('effective_at')->nullable();
            $table->foreignId('updated_by')->nullable()->constrained('admin_users')->nullOnDelete();
            $table->string('reason', 255)->nullable();
            $table->timestamps();
        });

        Schema::create('play_config_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('version_id')->constrained('play_config_versions')->cascadeOnDelete();
            $table->string('play_code', 32);
            $table->boolean('is_enabled')->default(true);
            $table->bigInteger('min_bet_amount')->default(0);
            $table->bigInteger('max_bet_amount')->default(0);
            $table->integer('display_order')->default(0);
            $table->text('rule_text_zh')->nullable();
            $table->text('rule_text_en')->nullable();
            $table->text('rule_text_ne')->nullable();
            $table->json('extra_config_json')->nullable();
            $table->timestamps();

            $table->unique(['version_id', 'play_code'], 'uk_play_config_items_version_play');
        });
    }

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