<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\MonitoringController;
use App\Http\Controllers\PasienController;
use App\Http\Controllers\PasienManagementController;
use App\Http\Controllers\GmfmController;

Route::get('/', function () {
    return view('beranda');
})->name('beranda');

/*
|--------------------------------------------------------------------------
| AUTH
|--------------------------------------------------------------------------
*/
require __DIR__.'/auth.php';

/*
|--------------------------------------------------------------------------
| ADMIN & TERAPIS
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:admin,terapis'])->group(function () {

    // DASHBOARD
    Route::get('/dashboard', [MonitoringController::class, 'index'])
        ->name('dashboard');

    // MONITORING
    Route::put('/monitoring/{monitoring}', [MonitoringController::class, 'update'])
        ->name('monitoring.update');

    Route::delete('/monitoring/{monitoring}', [MonitoringController::class, 'destroy'])
        ->name('monitoring.destroy');

    Route::post('/gmfm', [GmfmController::class, 'store'])
        ->name('gmfm.store');
});

// ADMIN & TERAPIS — Kelola User
Route::middleware(['auth', 'role:admin,terapis'])->prefix('admin')->group(function () {
    Route::get('/pasien', [PasienManagementController::class, 'index'])->name('admin.pasien.index');
    Route::post('/pasien', [PasienManagementController::class, 'store'])->name('admin.pasien.store');
    Route::put('/pasien/{user}', [PasienManagementController::class, 'update'])->name('admin.pasien.update');
    Route::delete('/pasien/{user}', [PasienManagementController::class, 'destroy'])->name('admin.pasien.destroy');
});

Route::middleware(['auth', 'role:pasien'])->group(function () {
    Route::get('/pasien', [PasienController::class, 'index'])->name('pasien.index');
    Route::get('/pasien/download-pdf', [PasienController::class, 'downloadPdf'])
        ->name('pasien.download.pdf');
});
