<?php

use App\Http\Controllers\Admin\AdminDashboardController;
use App\Http\Controllers\Admin\AdminAnalysisController;
use App\Http\Controllers\Admin\AdminQueryController;
use App\Http\Controllers\Admin\AdminUserController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\User\UserPageController;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;

Route::get('/', [LandingController::class, 'index'])->name('landing');

Auth::routes();

Route::get('/home', [HomeController::class, 'index'])->name('home');

Route::controller(UserPageController::class)->group(function () {
    Route::get('/about', 'about')->name('about');
    Route::get('/checker', 'checker')->name('checker');
    Route::get('/diseases', 'diseases')->name('diseases');
    Route::get('/book', 'book')->name('book');
    Route::get('/contact', 'contact')->name('contact');
    Route::post('/contact', 'storeContact')->name('contact.store');
});

Route::middleware(['auth', 'user.type:user'])->prefix('user')->name('user.')->group(function () {
    Route::get('/dashboard', [UserPageController::class, 'dashboard'])->name('dashboard');
    Route::get('/history', [UserPageController::class, 'history'])->name('history');
    Route::get('/profile', [ProfileController::class, 'user'])->name('profile');
    Route::patch('/profile/information', [ProfileController::class, 'updateInformation'])->name('profile.information');
    Route::patch('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password');
});

Route::post('/checker', [UserPageController::class, 'analyze'])->middleware('auth')->name('checker.analyze');

Route::middleware(['auth', 'user.type:admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [AdminDashboardController::class, 'index'])->name('dashboard');
    Route::get('/analyses', [AdminAnalysisController::class, 'index'])->name('analyses');
    Route::delete('/analyses/{analysis}', [AdminAnalysisController::class, 'destroy'])->name('analyses.destroy');
    Route::get('/profile', [ProfileController::class, 'admin'])->name('profile');
    Route::patch('/profile/information', [ProfileController::class, 'updateInformation'])->name('profile.information');
    Route::patch('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password');
    Route::get('/users', [AdminUserController::class, 'index'])->name('users');
    Route::get('/queries', [AdminQueryController::class, 'index'])->name('queries');
    Route::get('/queries/{query}', [AdminQueryController::class, 'show'])->name('queries.show');
    Route::patch('/queries/{query}/status', [AdminQueryController::class, 'toggleStatus'])->name('queries.status');
    Route::post('/clear-cache', function () {
        Artisan::call('optimize:clear');

        return back()->with('status', 'Application caches cleared successfully.');
    })->name('clear-cache');
});
