<?php

use Illuminate\Support\Facades\Route;
use Modules\LabCore\Http\Controllers\InstallController;
use Modules\LabCore\Http\Controllers\LabAgentController;
use Modules\LabCore\Http\Controllers\LabDashboardController;
use Modules\LabCore\Http\Controllers\LabDeviceController;
use Modules\LabCore\Http\Controllers\LabLogController;
use Modules\LabCore\Http\Controllers\LabSessionController;
use Modules\LabCore\Http\Controllers\LabSettingsController;
use Modules\LabCore\Http\Controllers\LabWorklistController;

// Install / Update routes
Route::middleware(['web', 'auth'])->prefix('lab')->group(function () {
    Route::get('/install',   [InstallController::class, 'index']);
    Route::post('/install',  [InstallController::class, 'install']);
    Route::get('/uninstall', [InstallController::class, 'uninstall']);
    Route::get('/update',    [InstallController::class, 'update']);
    Route::get('/repair',    [InstallController::class, 'repair']);
});

// Admin routes
Route::group([
    'middleware' => ['web', 'auth', 'SetSessionData', 'language', 'timezone', 'AdminSidebarMenu'],
    'prefix'     => 'lab',
], function () {

    Route::get('/', [LabDashboardController::class, 'index'])->name('lab.dashboard');

    // Bridge agents
    Route::get('/agents',                  [LabAgentController::class, 'index'])->name('lab.agents.index');
    Route::post('/agents',                 [LabAgentController::class, 'store'])->name('lab.agents.store');
    Route::post('/agents/{id}/token',      [LabAgentController::class, 'regenerateToken'])->name('lab.agents.token');
    Route::delete('/agents/{id}',          [LabAgentController::class, 'destroy'])->name('lab.agents.destroy');

    // Devices
    Route::get('/devices',                 [LabDeviceController::class, 'index'])->name('lab.devices.index');
    Route::post('/devices',                [LabDeviceController::class, 'store'])->name('lab.devices.store');
    Route::put('/devices/{id}',            [LabDeviceController::class, 'update'])->name('lab.devices.update');
    Route::delete('/devices/{id}',         [LabDeviceController::class, 'destroy'])->name('lab.devices.destroy');

    // Worklist
    Route::get('/worklist',                [LabWorklistController::class, 'index'])->name('lab.worklist.index');
    Route::get('/worklist/create',         [LabWorklistController::class, 'create'])->name('lab.worklist.create');
    Route::post('/worklist',               [LabWorklistController::class, 'store'])->name('lab.worklist.store');
    Route::delete('/worklist/{id}',        [LabWorklistController::class, 'destroy'])->name('lab.worklist.destroy');

    // Test results / sessions
    Route::get('/results',                 [LabSessionController::class, 'index'])->name('lab.results.index');
    Route::get('/results/{id}',            [LabSessionController::class, 'show'])->name('lab.results.show');
    Route::delete('/results/{id}',         [LabSessionController::class, 'destroy'])->name('lab.results.destroy');

    // Communication logs
    Route::get('/logs',                    [LabLogController::class, 'index'])->name('lab.logs.index');
    Route::delete('/logs/clear',           [LabLogController::class, 'clear'])->name('lab.logs.clear');

    // Settings
    Route::get('/settings',                [LabSettingsController::class, 'index'])->name('lab.settings.index');
    Route::put('/settings',                [LabSettingsController::class, 'update'])->name('lab.settings.update');
});
