<?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::table('odds_items', function (Blueprint $table) {
            // 添加 dimension 字段用于按 2D/3D/4D 配置佣金
            $table->unsignedTinyInteger('dimension')->nullable()->after('prize_scope')->comment('2/3/4 维度，佣金按维度配置');
            
            // 删除旧的唯一约束
            $table->dropUnique('uk_odds_items_version_play_prize_currency');
            
            // 添加新的唯一约束：佣金按 dimension + currency_code 配置
            // 赔率仍按 play_code + prize_scope + currency_code 配置
            $table->unique(
                ['version_id', 'play_code', 'prize_scope', 'currency_code', 'dimension'],
                'uk_odds_items_version_play_prize_currency_dimension'
            );
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('odds_items', function (Blueprint $table) {
            // 删除新的唯一约束
            $table->dropUnique('uk_odds_items_version_play_prize_currency_dimension');
            
            // 恢复旧的唯一约束
            $table->unique(
                ['version_id', 'play_code', 'prize_scope', 'currency_code'],
                'uk_odds_items_version_play_prize_currency'
            );
            
            // 删除 dimension 字段
            $table->dropColumn('dimension');
        });
    }
};
