<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\Web\AdminWebAuthController;
use App\Http\Controllers\Admin\Web\AdminDashboardController;
use App\Http\Controllers\Admin\Web\AdminWebMatchController;
use App\Http\Controllers\Admin\Web\AdminWebPollController;
use App\Http\Controllers\Admin\Web\AdminWebNewsController;
use App\Http\Controllers\Admin\Web\AdminWebUserController;

Route::get('/', fn () => redirect('/admin'));

Route::prefix('admin')->name('admin.')->group(function () {

    Route::middleware('guest')->group(function () {
        Route::get('/login',  [AdminWebAuthController::class, 'showLogin'])->name('login');
        Route::post('/login', [AdminWebAuthController::class, 'login'])->name('login.post');
    });

    Route::post('/logout', [AdminWebAuthController::class, 'logout'])->name('logout');

    Route::middleware('auth.admin.web')->group(function () {
        Route::get('/', [AdminDashboardController::class, 'index'])->name('dashboard');

        // Matches
        Route::prefix('matches')->name('matches.')->group(function () {
            Route::get('/',          [AdminWebMatchController::class, 'index'])->name('index');
            Route::get('/create',    [AdminWebMatchController::class, 'create'])->name('create');
            Route::post('/',         [AdminWebMatchController::class, 'store'])->name('store');
            Route::get('/{id}/edit', [AdminWebMatchController::class, 'edit'])->name('edit');
            Route::put('/{id}',      [AdminWebMatchController::class, 'update'])->name('update');
            Route::put('/{id}/ai-prediction', [AdminWebMatchController::class, 'updateAiPrediction'])->name('ai-prediction');
            Route::delete('/{id}',            [AdminWebMatchController::class, 'destroy'])->name('destroy');
        });

        // Polls
        Route::prefix('polls')->name('polls.')->group(function () {
            Route::get('/',                    [AdminWebPollController::class, 'index'])->name('index');
            Route::get('/create',              [AdminWebPollController::class, 'create'])->name('create');
            Route::post('/',                   [AdminWebPollController::class, 'store'])->name('store');
            Route::get('/{id}/edit',           [AdminWebPollController::class, 'edit'])->name('edit');
            Route::patch('/{id}/toggle',       [AdminWebPollController::class, 'toggle'])->name('toggle');
            Route::post('/{id}/manual-votes',  [AdminWebPollController::class, 'setManualVotes'])->name('manual-votes');
            Route::post('/{id}/reset-votes',   [AdminWebPollController::class, 'resetVotes'])->name('reset-votes');
            Route::delete('/{id}',             [AdminWebPollController::class, 'destroy'])->name('destroy');
        });

        // News
        Route::prefix('news')->name('news.')->group(function () {
            Route::get('/',          [AdminWebNewsController::class, 'index'])->name('index');
            Route::get('/create',    [AdminWebNewsController::class, 'create'])->name('create');
            Route::post('/',         [AdminWebNewsController::class, 'store'])->name('store');
            Route::get('/{id}/edit', [AdminWebNewsController::class, 'edit'])->name('edit');
            Route::put('/{id}',      [AdminWebNewsController::class, 'update'])->name('update');
            Route::delete('/{id}',   [AdminWebNewsController::class, 'destroy'])->name('destroy');
        });

        // Users
        Route::prefix('users')->name('users.')->group(function () {
            Route::get('/',              [AdminWebUserController::class, 'index'])->name('index');
            Route::patch('/{id}/ban',    [AdminWebUserController::class, 'ban'])->name('ban');
            Route::patch('/{id}/unban',  [AdminWebUserController::class, 'unban'])->name('unban');
            Route::delete('/{id}',       [AdminWebUserController::class, 'destroy'])->name('destroy');
        });
    });
});
