<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\V1\Admin\PlayTypeIndexController;
use App\Http\Controllers\Api\V1\Admin\PlayTypePatchController;
use App\Http\Controllers\Api\V1\Admin\Config\OddsVersionShowController;
use App\Http\Controllers\Api\V1\Admin\Config\OddsItemsReplaceController;
use App\Http\Controllers\Api\V1\Admin\Config\OddsVersionIndexController;
use App\Http\Controllers\Api\V1\Admin\Config\OddsVersionStoreController;
use App\Http\Controllers\Api\V1\Admin\Config\OddsVersionPublishController;
use App\Http\Controllers\Api\V1\Admin\Config\OddsVersionDestroyController;
use App\Http\Controllers\Api\V1\Admin\Config\RiskCapVersionShowController;
use App\Http\Controllers\Api\V1\Admin\Config\RiskCapItemsReplaceController;
use App\Http\Controllers\Api\V1\Admin\Config\RiskCapVersionIndexController;
use App\Http\Controllers\Api\V1\Admin\Config\RiskCapVersionStoreController;
use App\Http\Controllers\Api\V1\Admin\Config\PlayConfigVersionShowController;
use App\Http\Controllers\Api\V1\Admin\Config\RiskCapVersionPublishController;
use App\Http\Controllers\Api\V1\Admin\Config\PlayConfigItemsReplaceController;
use App\Http\Controllers\Api\V1\Admin\Config\PlayConfigVersionIndexController;
use App\Http\Controllers\Api\V1\Admin\Config\PlayConfigVersionStoreController;
use App\Http\Controllers\Api\V1\Admin\Config\PlayConfigVersionPublishController;
use App\Http\Controllers\Api\V1\Admin\Config\PlayConfigVersionDestroyController;
use App\Http\Controllers\Api\V1\Admin\Config\RiskCapVersionDestroyController;
use App\Http\Controllers\Api\V1\Admin\AdminSettingController;

/**
 * 管理员配置管理路由（玩法/赔率/封顶）。
 */

// 玩法类型只读
Route::middleware('admin.api-resource')
    ->get('play-types', PlayTypeIndexController::class)
    ->name('api.v1.admin.play-types.index');

// 玩法版本只读
Route::middleware('admin.api-resource')
    ->prefix('config')
    ->name('api.v1.admin.config.')
    ->group(function (): void {
        Route::get('play-versions', PlayConfigVersionIndexController::class)
            ->name('play-versions.index');
        Route::get('play-versions/{id}', PlayConfigVersionShowController::class)
            ->whereNumber('id')
            ->name('play-versions.show');
    });

// 赔率/回水只读
Route::middleware('admin.api-resource')
    ->prefix('config')
    ->name('api.v1.admin.config.')
    ->group(function (): void {
        Route::get('odds-versions', OddsVersionIndexController::class)
            ->name('odds-versions.index');
        Route::get('odds-versions/{id}', OddsVersionShowController::class)
            ->whereNumber('id')
            ->name('odds-versions.show');
    });

// 封顶只读
Route::middleware('admin.api-resource')
    ->prefix('config')
    ->name('api.v1.admin.config.')
    ->group(function (): void {
        Route::get('risk-cap-versions', RiskCapVersionIndexController::class)
            ->name('risk-cap-versions.index');
        Route::get('risk-cap-versions/{id}', RiskCapVersionShowController::class)
            ->whereNumber('id')
            ->name('risk-cap-versions.show');
    });

// 玩法/赔率/封顶/Jackpot 配置写入
Route::middleware('admin.api-resource')
    ->group(function (): void {
        Route::patch('play-types/{play_code}', PlayTypePatchController::class)
            ->where('play_code', '[a-z0-9_]+')
            ->name('api.v1.admin.play-types.patch');

        Route::prefix('config')
            ->name('api.v1.admin.config.')
            ->group(function (): void {
                // 玩法版本写入
                Route::post('play-versions', PlayConfigVersionStoreController::class)
                    ->name('play-versions.store');
                Route::put('play-versions/{id}/items', PlayConfigItemsReplaceController::class)
                    ->whereNumber('id')
                    ->name('play-versions.items.replace');
                Route::post('play-versions/{id}/publish', PlayConfigVersionPublishController::class)
                    ->whereNumber('id')
                    ->name('play-versions.publish');
                Route::delete('play-versions/{id}', PlayConfigVersionDestroyController::class)
                    ->whereNumber('id')
                    ->name('play-versions.destroy');

                // 赔率版本写入
                Route::post('odds-versions', OddsVersionStoreController::class)
                    ->name('odds-versions.store');
                Route::put('odds-versions/{id}/items', OddsItemsReplaceController::class)
                    ->whereNumber('id')
                    ->name('odds-versions.items.replace');
                Route::post('odds-versions/{id}/publish', OddsVersionPublishController::class)
                    ->whereNumber('id')
                    ->name('odds-versions.publish');
                Route::delete('odds-versions/{id}', OddsVersionDestroyController::class)
                    ->whereNumber('id')
                    ->name('odds-versions.destroy');

                // 封顶版本写入
                Route::post('risk-cap-versions', RiskCapVersionStoreController::class)
                    ->name('risk-cap-versions.store');
                Route::put('risk-cap-versions/{id}/items', RiskCapItemsReplaceController::class)
                    ->whereNumber('id')
                    ->name('risk-cap-versions.items.replace');
                Route::post('risk-cap-versions/{id}/publish', RiskCapVersionPublishController::class)
                    ->whereNumber('id')
                    ->name('risk-cap-versions.publish');
                Route::delete('risk-cap-versions/{id}', RiskCapVersionDestroyController::class)
                    ->whereNumber('id')
                    ->name('risk-cap-versions.destroy');
            });
    });

// 通用 KV 设置（钱包限额等）
Route::middleware('admin.api-resource')
    ->prefix('settings')
    ->name('api.v1.admin.settings.')
    ->group(function (): void {
        Route::get('deployment', [AdminSettingController::class, 'deployment'])
            ->name('deployment');
        Route::get('/', AdminSettingController::class.'@index')
            ->name('index');
        Route::put('batch', AdminSettingController::class.'@batchUpdate')
            ->name('batch-update');
        Route::put('{key}', AdminSettingController::class.'@update')
            ->name('update');
    });
