<?php

use Illuminate\Support\Facades\Route;
use Modules\MedNotify\Http\Controllers\InstallController;
use Modules\MedNotify\Http\Controllers\LogController;
use Modules\MedNotify\Http\Controllers\PreferenceController;
use Modules\MedNotify\Http\Controllers\TemplateController;

/*
|--------------------------------------------------------------------------
| MedNotify Back-Office (Blade, inside the ERP UI)
|--------------------------------------------------------------------------
| Session-authenticated routes rendered with the ERP master layout — the SAME
| middleware stack as the Vrc / MedRegistry modules. UI lives under
| `med-notify`. Controllers guard with mednotify.* permissions.
*/

// Install / Update routes (superadmin-gated inside the controller).
Route::middleware(['web', 'auth'])->prefix('med-notify')->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']);
});

// Back-office UI (P2-T1). Mirrors the Vrc middleware stack.
Route::middleware(['web', 'auth', 'SetSessionData', 'language', 'timezone', 'AdminSidebarMenu', 'module:MedNotify'])
    ->prefix('med-notify')
    ->name('mednotify.')
    ->group(function () {
        // Templates (per event × channel).
        Route::get('templates', [TemplateController::class, 'index'])->name('templates.index');
        Route::get('templates/edit', [TemplateController::class, 'edit'])->name('templates.edit');
        Route::post('templates', [TemplateController::class, 'update'])->name('templates.update');
        Route::post('templates/reset', [TemplateController::class, 'reset'])->name('templates.reset');

        // My preferences (event × channel matrix + digest + quiet hours).
        Route::get('preferences', [PreferenceController::class, 'edit'])->name('preferences.edit');
        Route::put('preferences', [PreferenceController::class, 'update'])->name('preferences.update');

        // Delivery log (DataTable + filters).
        Route::get('log', [LogController::class, 'index'])->name('log.index');
    });
