<?php

use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\Admin\SiswaController;
use App\Http\Controllers\Api\Admin\JurusanController;
use App\Http\Controllers\Api\Admin\GuruController;
use App\Http\Controllers\Api\Admin\AlumniController;
use App\Http\Controllers\Api\Admin\DashboardAdminController;
use App\Http\Controllers\Api\Admin\RiwayatController;
use App\Http\Controllers\Api\Admin\ProspekKerjaController;
use App\Http\Controllers\Api\Student\RecommendationApiController;
use App\Http\Controllers\Api\Student\DashboardStudentController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Authentication & Public Routes
|--------------------------------------------------------------------------
*/

Route::post('/login', [AuthController::class, 'login'])->name('api.login');

/*
|--------------------------------------------------------------------------
| Test Koneksi Laravel ke Flask PythonAnywhere
|--------------------------------------------------------------------------
*/
Route::get('/python/health', [RecommendationApiController::class, 'health'])
    ->name('api.python.health');

/*
|--------------------------------------------------------------------------
| Protected API Routes (Membutuhkan Login / Token Sanctum)
|--------------------------------------------------------------------------
*/
Route::middleware('auth:sanctum')->group(function () {

    /*
    |--------------------------------------------------------------------------
    | Admin Routes Group
    |--------------------------------------------------------------------------
    */
    Route::middleware('role:admin')->prefix('admin')->name('api.admin.')->group(function () {
        // Dashboard Stats
        Route::get('/dashboard-stats', [DashboardAdminController::class, 'index'])->name('dashboard-stats');

        // CRUD Master Data Siswa
        Route::apiResource('/siswa', SiswaController::class);

        // CRUD Master Data Lainnya
        Route::apiResource('/jurusan', JurusanController::class);
        Route::apiResource('/guru', GuruController::class);
        Route::apiResource('/alumni', AlumniController::class);
        Route::apiResource('/riwayat', RiwayatController::class);
        Route::apiResource('/prospek-kerja', ProspekKerjaController::class);
    });

    /*
    |--------------------------------------------------------------------------
    | Student (Siswa) Routes Group
    |--------------------------------------------------------------------------
    */
    Route::middleware('role:siswa')->prefix('student')->name('api.student.')->group(function () {
        Route::get('/dashboard-stats', [DashboardStudentController::class, 'index'])
            ->name('dashboard-stats');

        Route::post('/proses-rekomendasi', [RecommendationApiController::class, 'hitungPrediksi'])
            ->name('proses-rekomendasi');

        Route::get('/hasil-rekomendasi/{id}', [RecommendationApiController::class, 'getHasilRekomendasi'])
            ->name('hasil-rekomendasi');

        Route::post('/recommendation/predict', [RecommendationApiController::class, 'hitungPrediksi'])
            ->name('recommendation.predict');

        Route::get('/recommendation/result/{id}', [RecommendationApiController::class, 'getHasilRekomendasi'])
            ->name('recommendation.result');
    });

    /*
    |--------------------------------------------------------------------------
    | Logout
    |--------------------------------------------------------------------------
    */
    Route::post('/logout', [AuthController::class, 'logout'])->name('api.logout');
});