<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use Webman\Route;
use app\api\middleware\ApiAccessLogMiddleware;
use app\api\middleware\ApiKeyMiddleware;
use app\api\middleware\AuthTokenMiddleware;
use app\api\middleware\TokenMiddleware;

// 平台鉴权接口：/api/v1/authToken，请求头 signature/secret/time/agent_id，返回 authtToken
Route::group('/api/v1', function () {
    Route::any('/authToken', [app\api\controller\v1\AuthTokenController::class, 'index']);
})->middleware([
    ApiAccessLogMiddleware::class,
    ApiKeyMiddleware::class,
]);

// 平台 v1 接口：需在请求头携带 api-key、auth-token
Route::group('/api/v1', function () {
    Route::any('/getGameList', [app\api\controller\v1\GameController::class, 'getGameList']);
    Route::any('/getGameHall', [app\api\controller\v1\GameController::class, 'getGameHall']);
    Route::any('/getGameUrl', [app\api\controller\v1\GameController::class, 'getGameUrl']);
    Route::any('/getPlayerInfo', [app\api\controller\v1\GameController::class, 'getPlayerInfo']);
    Route::any('/getPlayerGameRecord', [app\api\controller\v1\GameController::class, 'getPlayerGameRecord']);
    Route::any('/getPlayerWalletRecord', [app\api\controller\v1\GameController::class, 'getPlayerWalletRecord']);
    Route::any('/getPlayerTicketRecord', [app\api\controller\v1\GameController::class, 'getPlayerTicketRecord']);
    Route::any('/setPlayerWallet', [app\api\controller\v1\GameController::class, 'setPlayerWallet']);
})->middleware([
    ApiAccessLogMiddleware::class,
    ApiKeyMiddleware::class,
    AuthTokenMiddleware::class,
]);

// 登录接口：无需 token，提交 JSON 获取带 token 的连接地址
Route::group('/api', function () {
    Route::any('/user/Login', [app\api\controller\UserController::class, 'Login']);
})->middleware([
    ApiAccessLogMiddleware::class,
]);

// 其余接口：仅经 token 中间件鉴权（header: token，base64(username.-.time)）
Route::group('/api', function () {
    Route::any('/user/logout', [app\api\controller\UserController::class, 'logout']);
    Route::any('/user/info', [app\api\controller\UserController::class, 'info']);
    Route::any('/user/balance', [app\api\controller\UserController::class, 'balance']);
    Route::any('/user/walletRecord', [app\api\controller\UserController::class, 'walletRecord']);
    Route::any('/user/playGameRecord', [app\api\controller\UserController::class, 'playGameRecord']);
    Route::any('/game/config', [app\api\controller\GameController::class, 'config']);
//    Route::any('/game/buyLotteryTickets', [app\api\controller\GameController::class, 'buyLotteryTickets']);
    Route::any('/game/lotteryPool', [app\api\controller\GameController::class, 'lotteryPool']);
    Route::any('/game/anteConfig', [app\api\controller\GameController::class, 'anteConfig']);
    Route::any('/game/playStart', [app\api\controller\GameController::class, 'playStart']);
})->middleware([
    ApiAccessLogMiddleware::class,
    TokenMiddleware::class,
]);

// 关闭主应用默认路由（/controller/action 隐式映射），未在本文件显式注册的路径返回 404
Route::disableDefaultRoute('');
