<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\EatingPatternController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\AuthController;

/*
|--------------------------------------------------------------------------
| Public Routes (Bisa diakses oleh Guest / Siapa saja tanpa Login)
|--------------------------------------------------------------------------
*/
// Halaman utama form input (diarahkan ke fungsi index agar statistik data ter-load)
Route::get('/', [EatingPatternController::class, 'index'])->name('home');

// Proses prediksi dan simpan data dari form kuesioner
Route::post('/predict', [EatingPatternController::class, 'predict']);


/*
|--------------------------------------------------------------------------
| Guest Routes (Hanya bisa diakses jika BELUM Login)
|--------------------------------------------------------------------------
*/
Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login']);
    Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('/register', [AuthController::class, 'register']);
});

/*
|--------------------------------------------------------------------------
| Auth Routes (Hanya bisa diakses jika SUDAH Login / Admin)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth'])->group(function () {
    // Melihat riwayat data (Hanya bisa diakses setelah login)
    Route::get('/history', [EatingPatternController::class, 'history'])->name('history');

    // Proses logout
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
});

/*
|--------------------------------------------------------------------------
| Admin Routes (Khusus Hak Akses Admin)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:admin'])->group(function () {
    Route::get('/admin', [AdminController::class, 'dashboard'])->name('admin.dashboard');
});