<?php

use Illuminate\Support\Facades\Route;
use Modules\Auth\Http\Controllers\EmailVerificationController;
use Modules\Auth\Http\Controllers\PasswordResetController;
use Modules\Auth\Http\Controllers\SessionController;
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\RegisteredUserController;

// Auth
Route::post('/register', [RegisteredUserController::class, 'store']);
Route::post('/login', [AuthenticatedSessionController::class, 'store'])->middleware('block.api.tools');

Route::post('/verify-email', [EmailVerificationController::class, 'verify'])
    ->middleware('throttle:email-verification');
Route::post('/verify-email/resend', [EmailVerificationController::class, 'resend'])
    ->middleware('throttle:email-verification-resend');

Route::post('/forgot-password', [PasswordResetController::class, 'requestOtp'])
    ->middleware('throttle:password-reset-request');
Route::post('/reset-password', [PasswordResetController::class, 'reset'])
    ->middleware('throttle:password-reset');

Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
    // get current user
    Route::get('/me', [SessionController::class, 'currentUser']);

    // switch active role
    Route::post('/active-role/switch', [SessionController::class, 'switchRole']);

    // logout
    Route::post('/logout', [AuthenticatedSessionController::class, 'destroy']);
});