<?php

use App\Http\Controllers\Admin\AccountController;
use App\Http\Controllers\Admin\InviteCodeController;
use App\Http\Controllers\Admin\LoginScreenNewsController;
use App\Http\Controllers\Admin\NewsController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\CabinetController;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\WowLoginNewsFeedController;
use Illuminate\Support\Facades\Route;

Route::get('/', [LandingController::class, 'index'])->name('landing.index');
Route::get('/launcher/login-news.txt', [WowLoginNewsFeedController::class, 'show'])->name('launcher.login-news.show');
Route::get('/appcast.xml', static fn() => Storage::disk('public')->get('appcast.xml'));
Route::post('/register', [LandingController::class, 'register'])
    ->middleware('throttle:8,1')
    ->name('game-account.store');

Route::middleware('guest')->group(function (): void {
    Route::get('/login', [LoginController::class, 'create'])->name('login');
    Route::post('/login', [LoginController::class, 'store'])
        ->middleware('throttle:10,1')
        ->name('login.store');
});

Route::middleware('auth')->group(function (): void {
    Route::post('/logout', [LoginController::class, 'destroy'])->name('logout');
    Route::get('/cabinet', [CabinetController::class, 'index'])->name('cabinet.index');
    Route::post('/cabinet/password', [CabinetController::class, 'updatePassword'])->name('cabinet.password.update');
    Route::get('/cabinet/client', [CabinetController::class, 'client'])->name('cabinet.client');
});

Route::middleware(['auth', 'gamemaster'])
    ->prefix('admin')
    ->name('admin.')
    ->group(function (): void {
        Route::get('/accounts', [AccountController::class, 'index'])->name('accounts.index');
        Route::patch('/accounts/{accountId}/access', [AccountController::class, 'updateAccess'])->name('accounts.access.update');
        Route::post('/invite-codes', [InviteCodeController::class, 'store'])->name('invite-codes.store');
        Route::get('/login-screen-news', [LoginScreenNewsController::class, 'index'])->name('login-screen-news.index');
        Route::post('/login-screen-news', [LoginScreenNewsController::class, 'store'])->name('login-screen-news.store');
        Route::patch('/login-screen-news/{newsItem}', [LoginScreenNewsController::class, 'update'])->name('login-screen-news.update');
        Route::delete('/login-screen-news/{newsItem}', [LoginScreenNewsController::class, 'destroy'])->name('login-screen-news.destroy');

        Route::get('/news', [NewsController::class, 'index'])->name('news.index');
        Route::post('/news', [NewsController::class, 'store'])->name('news.store');
        Route::patch('/news/{newsItem}', [NewsController::class, 'update'])->name('news.update');
        Route::delete('/news/{newsItem}', [NewsController::class, 'destroy'])->name('news.destroy');
    });
