<?php

use App\Http\Controllers\ApprovalController;
use App\Http\Controllers\AttendanceScheduleController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\DeviceController;
use App\Http\Controllers\DeviceScheduleController;
use App\Http\Controllers\ExculApprovalController;
use App\Http\Controllers\RegistrasiController;
use App\Http\Controllers\StudentController;
use Illuminate\Support\Facades\Route;

// Public routes - hanya login
Route::get('/', [AuthController::class, 'loginview'])->name('login');
Route::post('/login', [AuthController::class, 'login'])->name('login.post');

// Protected routes - harus login dulu
Route::middleware(['auth'])->group(function () {
    // dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    // perizinan
    Route::get('/perizinan', [\App\Http\Controllers\PerizinanController::class, 'index'])->name('perizinan.index');
    Route::get('/perizinan/{id}', [\App\Http\Controllers\PerizinanController::class, 'editView'])->name('perizinan.edit');
    Route::patch('/perizinan/{id}/validasi', [\App\Http\Controllers\PerizinanController::class, 'validasi'])->name('perizinan.validasi');

    // daftar excul
    Route::get('/daftarexcul',           [ExculApprovalController::class, 'index'])->name('index');
    Route::get('/excul/{id}',       [ExculApprovalController::class, 'show'])->name('excul-approval.show');
    Route::patch('/excul/{id}/approve', [ExculApprovalController::class, 'approve'])->name('excul-approve');
    Route::patch('/excul/{id}/reject',  [ExculApprovalController::class, 'reject'])->name('reject');

  Route::prefix('approvals')->name('approvals.')->group(function () {
      Route::get('/',              [ApprovalController::class, 'index'])->name('index');
      Route::get('/{id}',         [ApprovalController::class, 'show'])->name('show');
      Route::post('/{id}/approve',[ApprovalController::class, 'approve'])->name('approve');
      Route::post('/{id}/reject', [ApprovalController::class, 'reject'])->name('reject');
  });

  Route::prefix('registrasi')->name('registrasi.')->group(function () {
    Route::get('/', [RegistrasiController::class, 'index'])->name('index');
    Route::get('/{registrasi}', [RegistrasiController::class, 'show'])->name('show');
    Route::put('/{registrasi}/approve', [RegistrasiController::class, 'approve'])->name('approve');
    Route::put('/{registrasi}/reject', [RegistrasiController::class, 'reject'])->name('reject');
    });

    Route::get('/students', [StudentController::class, 'index'])->name('students.index');
    Route::get('/students/{studentId}/face/create', [StudentController::class, 'create'])->name('students.face.create');
    Route::post('/students/{studentId}/face', [StudentController::class, 'store'])->name('students.face.store');
    // tambahan ini
Route::get('/students/{studentId}/edit', [StudentController::class, 'edit'])->name('students.edit');
Route::put('/students/{studentId}', [StudentController::class, 'update'])->name('students.update');
Route::get('/students/face/bulk/create', [StudentController::class, 'bulkCreate'])->name('students.face.bulk.create');
Route::post('/students/face/bulk', [StudentController::class, 'bulkStore'])->name('students.face.bulk.store');

Route::get('/students/{studentId}/schedule', [StudentController::class, 'editSchedule'])->name('students.schedule.edit');

    Route::delete('/students/{studentId}/face', [StudentController::class, 'destroy'])->name('students.face.destroy');

    Route::get('/device', [DeviceController::class, 'index'])->name('devices.index');
    Route::get('/device/create', [DeviceController::class, 'create'])->name('devices.create');
    Route::post('/device', [DeviceController::class, 'store'])->name('devices.store');
    Route::get('/device/{device}/edit', [DeviceController::class, 'edit'])->name('devices.edit');
    Route::put('/device/{device}', [DeviceController::class, 'update'])->name('devices.update');
    Route::delete('/device/{device}', [DeviceController::class, 'destroy'])->name('devices.destroy');

    Route::post('/devices/{device}/test', [DeviceController::class, 'testConnection'])->name('devices.test');
    // routes/web.php
    Route::post('/students/{studentId}/schedule', [StudentController::class, 'updateSchedule'])->name('students.schedule.update');
    Route::post('/device/check-facelib', [DeviceController::class, 'checkFaceLibType'])->name('devices.check-facelib');
    Route::post('/device/{device}/capabilities', [DeviceController::class, 'capabilities'])->name('devices.capabilities');


    Route::prefix('devices/{device}/schedules')->group(function () {
        Route::get('/', [DeviceScheduleController::class, 'index'])->name('devices.schedules.index');
        Route::get('/create', [DeviceScheduleController::class, 'create'])->name('devices.schedules.create');
        Route::post('/', [DeviceScheduleController::class, 'store'])->name('devices.schedules.store');
        Route::post('/{schedule}/sync', [DeviceScheduleController::class, 'sync'])->name('devices.schedules.sync');
        Route::delete('/{schedule}', [DeviceScheduleController::class, 'destroy'])->name('devices.schedules.destroy');
    });

    Route::post('/devices/check-fdid', [DeviceController::class, 'checkFdid'])->name('devices.check-fdid');
    Route::post('/devices/check-door', [DeviceController::class, 'checkDoorCapabilities'])->name('devices.check-door');
    Route::post('/devices/check-work-mode', [DeviceController::class, 'checkWorkMode'])->name('devices.check-work-mode');
    Route::post('/devices/{device}/apply-work-mode', [DeviceController::class, 'applyWorkMode'])->name('devices.apply-work-mode');

    Route::post('/devices/{device}/fdid', [DeviceController::class, 'fdid'])->name('devices.fdid');
    Route::post('/devices/{device}/door-capabilities', [DeviceController::class, 'doorCapabilities'])->name('devices.door-capabilities');
    Route::post('/devices/{device}/work-mode', [DeviceController::class, 'workMode'])->name('devices.work-mode');


});

