<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\{
    AbsensiController,
    NilaiSantriController,
    CatatanKesehatanController,
    PrestasiController,
    PelanggaranController,
    BeritaController,
    AlumniController,
    PembayaranController,
    KelasController,
    FcmTokenController,
    ProfileController
};
use App\Http\Controllers\Api\ForgotPasswordController;

Route::post('/forgot-password/validate-nis', [ForgotPasswordController::class, 'validateNIS']);
Route::post('/forgot-password/reset', [ForgotPasswordController::class, 'resetPassword']);

// 📌 AUTH - Login & Logout
Route::post('/login', [AuthController::class, 'login']);

// 📌 Middleware Sanctum (Harus login)
Route::middleware(['auth:sanctum'])->group(function () {
    // 🔓 Logout & Get Info User
    Route::post('/logout', [AuthController::class, 'logout']);
    Route::get('/me', [AuthController::class, 'me']);
    Route::get('/santri/me', [ProfileController::class, 'santriProfile']);
    Route::post('/santri/me', [ProfileController::class, 'updateSantriProfile']);

    Route::get('/ping', function () {
        return response()->json(['status' => 'ok']);
    });

    Route::get('/absensi', [AbsensiController::class, 'index']);
    Route::post('/absensi', [AbsensiController::class, 'store']);
    Route::get('/nilai', [NilaiSantriController::class, 'index']);
    Route::get('/kesehatan', [CatatanKesehatanController::class, 'index']);
    Route::get('/prestasi', [PrestasiController::class, 'index']);
    Route::get('/pelanggaran', [PelanggaranController::class, 'index']);
    Route::get('/berita', [BeritaController::class, 'index']);
    Route::get('/berita/published', [BeritaController::class, 'published']);
    Route::get('/berita/{id}', [BeritaController::class, 'show']);
    Route::get('/alumni', [AlumniController::class, 'index']);
    Route::get('/pembayaran', [PembayaranController::class, 'index']);
    Route::post('/pembayaran', [PembayaranController::class, 'store']);
    Route::get('/kelas', [KelasController::class, 'index']);
    Route::get('/kelas/{id}', [KelasController::class, 'show']);
});
Route::middleware('auth:sanctum')->put('/password', [ProfileController::class, 'changePassword']);
Route::middleware('auth:api')->post('/fcm-token', [FcmTokenController::class, 'store']);
