<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\V1\Player\MeController;
use App\Http\Controllers\Api\V1\Wallet\WalletLogsController;
use App\Http\Controllers\Api\V1\Ticket\TicketPlaceController;
use App\Http\Controllers\Api\V1\Ticket\TicketPreviewController;
use App\Http\Controllers\Api\V1\Wallet\WalletBalanceController;
use App\Http\Controllers\Api\V1\Ticket\TicketItemShowController;
use App\Http\Controllers\Api\V1\Ticket\TicketItemsIndexController;
use App\Http\Controllers\Api\V1\Wallet\WalletTransferInController;
use App\Http\Controllers\Api\V1\Ticket\TicketDrawMyMatchController;
use App\Http\Controllers\Api\V1\Wallet\WalletTransferOutController;

/**
 * 玩家端路由（需 middleware lottery.player）。
 */
Route::middleware('lottery.player')->group(function (): void {
    // 当前登录玩家信息
    Route::prefix('player')
        ->name('api.v1.player.')
        ->group(function (): void {
            Route::get('me', MeController::class)->name('me');
        });

    // 钱包
    Route::prefix('wallet')
        ->name('api.v1.wallet.')
        ->group(function (): void {
            Route::get('balance', WalletBalanceController::class)->name('balance');
            Route::get('logs', WalletLogsController::class)->name('logs');
            Route::post('transfer-in', WalletTransferInController::class)->name('transfer-in');
            Route::post('transfer-out', WalletTransferOutController::class)->name('transfer-out');
        });

    // 注单
    Route::prefix('ticket')
        ->name('api.v1.ticket.')
        ->group(function (): void {
            Route::post('preview', TicketPreviewController::class)->name('preview');
            Route::post('place', TicketPlaceController::class)->name('place');
            Route::get('items', TicketItemsIndexController::class)->name('items.index');
            Route::get('items/{ticket_no}', TicketItemShowController::class)
                ->where('ticket_no', 'TK[0-9]+')
                ->name('items.show');
            Route::get('draws/{draw_no}/my-match', TicketDrawMyMatchController::class)
                ->where('draw_no', '[0-9]{8}-[0-9]{3}')
                ->name('draws.my-match');
        });
});
