<?php

use App\Http\Controllers\ManagementAlertController;
use App\Http\Controllers\ManagementCalendarController;
use App\Http\Controllers\TaskController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth','module:tasks'])->group(function (): void {
    Route::get('/tasks',[TaskController::class,'index'])->middleware('permission:tasks.view')->name('tasks.index');
    Route::get('/tasks/create',[TaskController::class,'create'])->middleware('permission:tasks.create')->name('tasks.create');
    Route::post('/tasks',[TaskController::class,'store'])->middleware('permission:tasks.create')->name('tasks.store');
    Route::get('/tasks/{task}',[TaskController::class,'show'])->middleware(['permission:tasks.view','can:view,task'])->name('tasks.show');
    Route::get('/tasks/{task}/edit',[TaskController::class,'edit'])->middleware(['permission:tasks.update','can:update,task'])->name('tasks.edit');
    Route::put('/tasks/{task}',[TaskController::class,'update'])->middleware(['permission:tasks.update','can:update,task'])->name('tasks.update');
    Route::post('/tasks/{task}/status',[TaskController::class,'status'])->middleware(['permission:tasks.update-status','can:updateStatus,task'])->name('tasks.status');
});

Route::middleware(['auth','module:calendar'])->group(function (): void {
    Route::get('/calendar',[ManagementCalendarController::class,'index'])->middleware('permission:calendar.view')->name('calendar.index');
    Route::post('/calendar/appointments',[ManagementCalendarController::class,'storeAppointment'])->middleware('permission:appointments.create')->name('calendar.appointments.store');
    Route::post('/calendar/appointments/{appointment}/status',[ManagementCalendarController::class,'appointmentStatus'])->middleware(['permission:appointments.manage-status','can:manageStatus,appointment'])->name('calendar.appointments.status');
});

Route::middleware('auth')->group(function (): void {
    Route::get('/management-alerts',[ManagementAlertController::class,'index'])->middleware('permission:management-alerts.view')->name('management-alerts.index');
    Route::post('/management-alerts/{alert}/acknowledge',[ManagementAlertController::class,'acknowledge'])->middleware(['permission:management-alerts.acknowledge','can:acknowledge,alert'])->name('management-alerts.acknowledge');
    Route::post('/management-alerts/{alert}/resolve',[ManagementAlertController::class,'resolve'])->middleware(['permission:management-alerts.resolve','can:resolve,alert'])->name('management-alerts.resolve');
    Route::put('/management-alert-settings',[ManagementAlertController::class,'settings'])->middleware('permission:management-alerts.settings')->name('management-alerts.settings');
});
