<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawShowController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawIndexController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawReopenController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawCancelController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawRngRunController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawStoreController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawUpdateController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawDestroyController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawBatchDestroyController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawPlanGenerateController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawSettlementRunController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawManualCloseController;
use App\Http\Controllers\Api\V1\Admin\Risk\AdminRiskPoolShowController;
use App\Http\Controllers\Api\V1\Admin\Risk\AdminRiskPoolIndexController;
use App\Http\Controllers\Api\V1\Admin\Risk\AdminRiskPoolManualStatusController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawResultBatchPublishController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawResultBatchDestroyController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawFinanceSummaryController;
use App\Http\Controllers\Api\V1\Admin\Risk\AdminRiskPoolLockLogIndexController;
use App\Http\Controllers\Api\V1\Admin\Draw\AdminDrawResultBatchesIndexController;
use App\Http\Controllers\Api\V1\Admin\Draw\DrawManualResultBatchStoreController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchShowController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchIndexController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchExportController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchPayoutController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchAdjustmentController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchRejectController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchApproveController;
use App\Http\Controllers\Api\V1\Admin\Settlement\AdminSettlementBatchDetailsController;

/**
 * 管理员开奖/风控/结算路由。
 */

// 开奖结果查看 + 风控监控
Route::middleware('admin.api-resource')
    ->group(function (): void {
        Route::get('draws', AdminDrawIndexController::class)
            ->name('api.v1.admin.draws.index');
        Route::get('draws/{draw}', AdminDrawShowController::class)
            ->name('api.v1.admin.draws.show');
        Route::get('draws/{draw}/finance-summary', AdminDrawFinanceSummaryController::class)
            ->name('api.v1.admin.draws.finance-summary');
        Route::get('draws/{draw}/result-batches', AdminDrawResultBatchesIndexController::class)
            ->name('api.v1.admin.draws.result-batches.index');
        Route::get('draws/{draw}/risk-pools/{number_4d}', AdminRiskPoolShowController::class)
            ->where('number_4d', '[0-9]{4}')
            ->name('api.v1.admin.draws.risk-pools.show');
        Route::get('draws/{draw}/risk-pool-lock-logs', AdminRiskPoolLockLogIndexController::class)
            ->name('api.v1.admin.draws.risk-pool-lock-logs.index');
        Route::get('draws/{draw}/risk-pools', AdminRiskPoolIndexController::class)
            ->name('api.v1.admin.draws.risk-pools.index');
    });

// 开奖结果录入（发布批次）
Route::middleware('admin.api-resource')
    ->group(function (): void {
        Route::post('draws/{draw}/result-batches', DrawManualResultBatchStoreController::class)
            ->name('api.v1.admin.draws.result-batches.store');
        Route::post('draws/{draw}/result-batches/{batch}/publish', DrawResultBatchPublishController::class)
            ->name('api.v1.admin.draws.result-batches.publish');
        Route::delete('draws/{draw}/result-batches/{batch}', DrawResultBatchDestroyController::class)
            ->name('api.v1.admin.draws.result-batches.destroy');
        Route::post('draws/{draw}/reopen', DrawReopenController::class)
            ->name('api.v1.admin.draws.reopen');
        Route::post('draws/generate-plan', DrawPlanGenerateController::class)
            ->name('api.v1.admin.draws.generate-plan');
        Route::post('draws', AdminDrawStoreController::class)
            ->name('api.v1.admin.draws.store');
        Route::put('draws/{draw}', AdminDrawUpdateController::class)
            ->name('api.v1.admin.draws.update');
        Route::delete('draws/{draw}', AdminDrawDestroyController::class)
            ->name('api.v1.admin.draws.destroy');
        Route::post('draws/batch-destroy', AdminDrawBatchDestroyController::class)
            ->name('api.v1.admin.draws.batch-destroy');
        Route::post('draws/{draw}/manual-close', DrawManualCloseController::class)
            ->name('api.v1.admin.draws.manual-close');
        Route::post('draws/{draw}/risk-pools/{number_4d}/manual-close', [AdminRiskPoolManualStatusController::class, 'close'])
            ->where('number_4d', '[0-9]{4}')
            ->name('api.v1.admin.draws.risk-pools.manual-close');
        Route::post('draws/{draw}/risk-pools/{number_4d}/recover', [AdminRiskPoolManualStatusController::class, 'recover'])
            ->where('number_4d', '[0-9]{4}')
            ->name('api.v1.admin.draws.risk-pools.recover');
        Route::post('draws/{draw}/cancel', DrawCancelController::class)
            ->name('api.v1.admin.draws.cancel');
        Route::post('draws/{draw}/rng', DrawRngRunController::class)
            ->name('api.v1.admin.draws.rng');
    });

// 派彩确认
Route::middleware('admin.api-resource')
    ->post('draws/{draw}/settlement/run', DrawSettlementRunController::class)
    ->name('api.v1.admin.draws.settlement.run');

// 结算批次查看
Route::middleware('admin.api-resource')
    ->group(function (): void {
        Route::get('settlement-batches', AdminSettlementBatchIndexController::class)
            ->name('api.v1.admin.settlement-batches.index');
        Route::get('settlement-batches/{batch}', AdminSettlementBatchShowController::class)
            ->name('api.v1.admin.settlement-batches.show');
        Route::get('settlement-batches/{batch}/details', AdminSettlementBatchDetailsController::class)
            ->name('api.v1.admin.settlement-batches.details');
        Route::get('settlement-batches/{batch}/export', AdminSettlementBatchExportController::class)
            ->name('api.v1.admin.settlement-batches.export');
    });

Route::middleware('admin.api-resource')
    ->group(function (): void {
        Route::post('settlement-batches/{batch}/approve', AdminSettlementBatchApproveController::class)
            ->name('api.v1.admin.settlement-batches.approve');
        Route::post('settlement-batches/{batch}/reject', AdminSettlementBatchRejectController::class)
            ->name('api.v1.admin.settlement-batches.reject');
    });

Route::middleware('admin.api-resource')
    ->post('settlement-batches/{batch}/payout', AdminSettlementBatchPayoutController::class)
    ->name('api.v1.admin.settlement-batches.payout');

Route::middleware('admin.api-resource')
    ->post('settlement-batches/{batch}/adjustments', AdminSettlementBatchAdjustmentController::class)
    ->name('api.v1.admin.settlement-batches.adjustments.store');
