<?php

use App\Http\Controllers\Accounts\CreateSystemUserController;
use App\Http\Controllers\Accounts\UserAuthenticationLogoutController;
use App\Http\Controllers\Accounts\RefreshAuthenticationTokenController;
use App\Http\Controllers\Accounts\UserAuthenticationController;
use App\Http\Controllers\Accounts\CheckEmailController;
use App\Http\Controllers\Accounts\GeneratePasswordResetController;
use App\Http\Controllers\Accounts\ResetPasswordController;
use App\Http\Controllers\Accounts\CreateCustomerController;
use App\Http\Controllers\Accounts\UserEmailVerificationController;
use App\Http\Controllers\Accounts\ResendEmailVerificationController;
use App\Http\Controllers\Accounts\FetchUserByEmailController;
use App\Http\Controllers\Accounts\FetchUserController;
use App\Http\Controllers\Accounts\ListUsersController;
use App\Http\Controllers\Accounts\UpdateUserController;
use App\Http\Controllers\Accounts\CreateAdminUserController;
use App\Http\Controllers\Accounts\DeleteUserController;
use App\Http\Controllers\Accounts\UpdateUserRoleController;
use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'account', 'as' => 'account.'], function () {

    Route::group(['prefix' => 'authentication', 'as' => 'authentication.'], function () {


        Route::group(['middleware' => 'valid.token'], function () {
            Route::get('/logout', [UserAuthenticationLogoutController::class, 'logout'])->name('logout');
            Route::get('/refresh', [RefreshAuthenticationTokenController::class, 'refresh'])->name('refresh');
        });

         Route::group(['prefix' => 'login', 'as' => 'authenticate.'], function () {
            Route::post('/attempt', [UserAuthenticationController::class, 'authenticate'])->name('attempt');
            Route::post('/check_email', [CheckEmailController::class, 'check'])->name('email.check');
         });

         Route::group(['prefix' => 'password', 'as' => 'password.'], function () {
            Route::post('/forget', [GeneratePasswordResetController::class, 'generate'])->name('forget');
            Route::post('/reset', [ResetPasswordController::class, 'reset'])->name('reset');
         });

    });

    Route::group(['prefix' => 'registration', 'as' => 'registration.'], function () {
        Route::post('/registration', [CreateCustomerController::class, 'create'])->name('register');
    });

    Route::group(['prefix' => 'email', 'as' => 'email.'], function () {
        Route::post('/verify', [UserEmailVerificationController::class, 'verify'])->name('verify');
        Route::post('/verification/resend', [ResendEmailVerificationController::class, 'resend'])->name('verification.resend');
    });

    Route::group(['prefix' => 'user', 'as' => 'user.', 'middleware' => 'valid.token'], function () {
        Route::get('email/{email}', [FetchUserByEmailController::class, 'fetch'])->name('company');
        Route::post('/show', [FetchUserController::class, 'fetch'])->name('show');
        Route::get('/list', [ListUsersController::class, 'list'])->name('list');
        Route::put('/update/{id}', [UpdateUserController::class, 'update'])->name('update');

        Route::post('/admin/create', [CreateAdminUserController::class, 'create'])->name('admin.create');
        Route::delete('/delete/{id}', [DeleteUserController::class, 'delete'])->name('delete');
        Route::put('/update/{id}/role', [UpdateUserRoleController::class, 'update'])->name('update.role');
        Route::post('/system/create', [CreateSystemUserController::class, 'create'])->name('system.create');
    });



});
