<?php

use App\Http\Controllers\ApiRootController;
use App\Http\Controllers\InstallNoxpayController;
use App\Http\Controllers\LegacyApiController;
use App\Http\Controllers\LegacyFunctionController;
use App\Http\Controllers\LegacyWebController;
use App\Http\Controllers\OpenGameController;
use Illuminate\Support\Facades\Route;

Route::domain('opengame.noxpay.club')->group(function (): void {
    Route::get('/', [OpenGameController::class, 'launch']);
    Route::get('/index.php', [OpenGameController::class, 'launch']);
    Route::get('/index', [OpenGameController::class, 'launch']);
});

Route::domain('api.noxpay.club')->group(function (): void {
    Route::get('/', [ApiRootController::class, 'denied']);
    Route::get('/index.php', [ApiRootController::class, 'denied']);
    Route::get('/index.html', [ApiRootController::class, 'denied']);
    Route::get('/v1', [ApiRootController::class, 'denied']);
    Route::get('/v1/index.php', [ApiRootController::class, 'denied']);
});

Route::get('/installnoxpay', [InstallNoxpayController::class, 'show']);
Route::post('/installnoxpay', [InstallNoxpayController::class, 'install']);

Route::match(['GET', 'POST'], '/', [LegacyWebController::class, 'index']);
Route::match(['GET', 'POST'], '/index', [LegacyWebController::class, 'index']);
Route::match(['GET', 'POST'], '/index.php', [LegacyWebController::class, 'index']);
Route::match(['GET', 'POST'], '/login', [LegacyWebController::class, 'login']);
Route::match(['GET', 'POST'], '/login.php', [LegacyWebController::class, 'login']);
Route::match(['GET', 'POST'], '/function.ashx.php', [LegacyWebController::class, 'license']);

Route::match(['GET', 'POST'], '/function/{script}', [LegacyFunctionController::class, 'run'])
    ->where('script', '.*\.php');

Route::match(['GET', 'POST'], '/v1/{script}', [LegacyApiController::class, 'run'])
    ->where('script', '.*\.(php|aspx|ashx)');

Route::match(['GET', 'POST'], '/api/v1/{script}', [LegacyApiController::class, 'run'])
    ->where('script', '.*\.(php|aspx|ashx)');

Route::match(['GET', 'POST'], '/{page}', [LegacyWebController::class, 'page'])
    ->where('page', '[A-Za-z0-9_]+');
