<?php

use LaraBB\Admin\Middleware\CheckAdmin;
use LaraBB\User\UI\Web\Handlers\Admin\CreateHandler;
use LaraBB\User\UI\Web\Handlers\Admin\DestroyHandler;
use LaraBB\User\UI\Web\Handlers\Admin\EditHandler;
use LaraBB\User\UI\Web\Handlers\Admin\IndexHandler;
use LaraBB\User\UI\Web\Handlers\Admin\StoreHandler;
use LaraBB\User\UI\Web\Handlers\Admin\UpdateHandler;
use LaraBB\User\UI\Web\Handlers\LoginHandler;
use LaraBB\User\UI\Web\Handlers\LoginPageHandler;
use LaraBB\User\UI\Web\Handlers\LogoutHandler;
use LaraBB\User\UI\Web\Handlers\LostPasswordHandler;
use LaraBB\User\UI\Web\Handlers\LostPasswordPageHandler;
use LaraBB\User\UI\Web\Handlers\RegisterConfirmHandler;
use LaraBB\User\UI\Web\Handlers\RegisterHandler;
use LaraBB\User\UI\Web\Handlers\RegisterPageHandler;

Route::group([
    'prefix' => 'user'
], function() {
    // Non-authenticated user actions
    Route::get('register/{invitecode?}', RegisterPageHandler::class)->name('register-page');
    Route::post('register', RegisterHandler::class)->name('register');
    Route::post('register/confirm', RegisterConfirmHandler::class)->name('register-confirm');
    Route::get('login', LoginPageHandler::class)->name('login-page');
    Route::post('login', LoginHandler::class)->name('login');
    Route::get('lostpassword', LostPasswordPageHandler::class)->name('lost-password-page');
    Route::post('lostpassword', LostPasswordHandler::class)->name('lost-password');

    // Authenticated user actions
    Route::group([
        'middleware' => [
            'auth'
        ]
    ], function() {
        Route::post('logout', LogoutHandler::class)->name('logout');
    });
});

// Admin User routes
Route::group([
    'prefix' => 'admin/user',
    'middleware' => [
        'auth',
        CheckAdmin::class
    ]
], function() {
    Route::get('/', IndexHandler::class)->name('admin.users');
    Route::get('create', CreateHandler::class)->name('admin.users.create');
    Route::get('{uuid}', EditHandler::class)->name('admin.users.edit');
    Route::post('store', StoreHandler::class)->name('admin.users.store');
    Route::post('update', UpdateHandler::class)->name('admin.users.update');
    Route::post('destroy', DestroyHandler::class)->name('admin.users.destroy');
});
