<?php

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\LogoutController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    if (! Auth::check()) {
        return redirect()->route('login');
    }

    return redirect()->route(app(\App\Services\Auth\PortalRedirectService::class)->homeRouteName(Auth::user()));
});

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

Route::post('/logout', [LogoutController::class, 'destroy'])
    ->middleware('auth')
    ->name('logout');

Route::patch('/profile/theme', [\App\Http\Controllers\ThemePreferenceController::class, 'update'])
    ->middleware('auth')
    ->name('profile.theme');

Route::get('/api/docs', [\App\Http\Controllers\ApiDocumentationController::class, 'index'])->name('api.docs');
