<?php

use App\Http\Controllers\CameraController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\DeviceController;
use App\Http\Controllers\HealthController;
use App\Http\Controllers\ImageController;
use App\Http\Controllers\LogController;
use App\Http\Controllers\MapController;
use App\Http\Controllers\ScheduleController;
use App\Http\Controllers\ScheduleLogController;
use App\Http\Controllers\SendController;
use Illuminate\Support\Facades\Route;

Route::prefix('lis-portal')->name('lis.')->group(function () {

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

    // Devices
    Route::resource('devices', DeviceController::class)->except(['show']);

    // Schedule
    Route::get ('schedule',              [ScheduleController::class, 'index'])  ->name('schedule.index');
    Route::put ('schedule/{device}',     [ScheduleController::class, 'update']) ->name('schedule.update');
    Route::post('schedule/{device}/run', [ScheduleController::class, 'runNow'])->name('schedule.run');

    // Send
    Route::get ('send',               [SendController::class, 'index'])    ->name('send.index');
    Route::post('send',               [SendController::class, 'send'])     ->name('send.send');
    Route::post('send/{device}/quick',[SendController::class, 'quickSend'])->name('send.quick');

    // Panel images (serves buka.jpg / tutup.jpg from storage)
    Route::get('panel-image/{mode}', [ImageController::class, 'panel'])->name('panel-image');

    // Map
    Route::get ('map',         [MapController::class, 'index'])   ->name('map.index');
    Route::get ('map/devices', [MapController::class, 'devices']) ->name('map.devices');

    // Health
    Route::get ('health',              [HealthController::class, 'index'])  ->name('health.index');
    Route::post('health/{device}/ping',[HealthController::class, 'ping'])   ->name('health.ping');
    Route::post('health/ping-all',     [HealthController::class, 'pingAll'])->name('health.pingAll');

    // Logs
    Route::get   ('logs',        [LogController::class, 'index'])->name('log.index');
    Route::delete('logs/clear',  [LogController::class, 'clear'])->name('log.clear');

    // Schedule log files
    Route::get('schedule-log',          [ScheduleLogController::class, 'index'])   ->name('schedule-log.index');
    Route::get('schedule-log/download', [ScheduleLogController::class, 'download'])->name('schedule-log.download');

    // RTSP Cameras
    Route::get   ('cameras',                   [CameraController::class, 'index'])   ->name('cameras.index');
    Route::post  ('cameras',                   [CameraController::class, 'store'])   ->name('cameras.store');
    Route::put   ('cameras/{camera}',          [CameraController::class, 'update'])  ->name('cameras.update');
    Route::delete('cameras/{camera}',          [CameraController::class, 'destroy']) ->name('cameras.destroy');
    Route::get   ('cameras/{camera}/snapshot', [CameraController::class, 'snapshot'])->name('cameras.snapshot');
});

// Redirect root to portal
Route::get('/', fn() => redirect('/lis-portal'));
