<?php


use Artisan;
use Empresa\ContactoSmsController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\AlertaController;
use App\Http\Controllers\EmpresaController;
use App\Http\Controllers\EmpleadoController;
use App\Http\Controllers\OperadorController;
use App\Http\Controllers\SeguridadController;
use App\Http\Controllers\SuperadminController;
use App\Http\Controllers\UsuarioFinalController;

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::middleware(['auth', 'role:superadmin'])->prefix('superadmin')->name('superadmin.')->group(function () {
    Route::get('/dashboard', [SuperAdminController::class, 'dashboard'])->name('dashboard');

    Route::get('/usuarios', [App\Http\Controllers\Superadmin\UserController::class, 'index'])->name('usuarios.index');
    Route::get('/usuarios/create', [App\Http\Controllers\Superadmin\UserController::class, 'create'])->name('usuarios.create');
    Route::get('/usuarios/{usuario}', [App\Http\Controllers\Superadmin\UserController::class, 'show'])->name('usuarios.show');
    Route::post('/usuario', [App\Http\Controllers\Superadmin\UserController::class, 'store'])->name('usuarios.store');
    Route::get('/usuarios/{usuario}/edit', [App\Http\Controllers\Superadmin\UserController::class, 'edit'])->name('usuarios.edit');
    Route::post('/usuarios/{usuario}', [App\Http\Controllers\Superadmin\UserController::class, 'update'])->name('usuarios.update');
    Route::delete('/usuarios/{usuario}', [App\Http\Controllers\Superadmin\UserController::class, 'destroy'])->name('usuarios.destroy');

    Route::get('/empresas', [App\Http\Controllers\Superadmin\EmpresaController::class, 'index'])->name('empresas.index');
    Route::get('/empresas/create', [App\Http\Controllers\Superadmin\EmpresaController::class, 'create'])->name('empresas.create');
    Route::get('/empresas/{empresa}', [App\Http\Controllers\Superadmin\EmpresaController::class, 'show'])->name('empresas.show');
    Route::post('/empresa', [App\Http\Controllers\Superadmin\EmpresaController::class, 'store'])->name('empresas.store');
    Route::get('/empresas/{empresa}/edit', [App\Http\Controllers\Superadmin\EmpresaController::class, 'edit'])->name('empresas.edit');
    Route::post('/empresas/{empresa}', [App\Http\Controllers\Superadmin\EmpresaController::class, 'update'])->name('empresas.update');
    Route::delete('/empresas/{empresa}', [App\Http\Controllers\Superadmin\EmpresaController::class, 'destroy'])->name('empresas.destroy');

    Route::resource('empresas', \App\Http\Controllers\Superadmin\EmpresaController::class);
   
});

Route::middleware(['auth', 'role:empresa_admin'])->prefix('empresa')->name('empresa.')->group(function () {
    Route::get('/empresa/dashboard', [EmpresaController::class, 'dashboard'])->name('dashboard');
    Route::get('/configuracion', [EmpresaController::class, 'configuracion'])->name('configuracion');

    Route::get('/dashboard', [\App\Http\Controllers\Empresa\AlertaController::class, 'index'])->name('alertas.index');
    Route::resource('contactos-sms', \App\Http\Controllers\Empresa\ContactoSmsController::class);
    Route::resource('contactos-sms', \App\Http\Controllers\Empresa\ContactoSmsController::class);
  
    Route::post('/alertas/{alerta}/estado', [\App\Http\Controllers\Empresa\AlertaController::class, 'cambiarEstado'])
    ->name('alertas.estado');
    Route::delete('/alertas/{alerta}', [\App\Http\Controllers\Empresa\AlertaController::class, 'destroy'])
    ->name('alertas.destroy');
    Route::get('/alertas/{alerta}', [\App\Http\Controllers\Empresa\AlertaController::class, 'show'])
    ->name('alertas.show');

     
});


Route::middleware(['auth', 'role:empleado'])->prefix('empleado')->name('empleado.')->group(function () {
    Route::get('/dashboard', [EmpleadoController::class, 'dashboard'])->name('dashboard');
});

Route::middleware(['auth', 'role:usuario_final'])->group(function () {
    Route::get('/usuario/home', [UsuarioFinalController::class, 'index']);
});

Route::middleware(['auth', 'role:operador'])->group(function () {
    Route::get('/operador/alertas', [OperadorController::class, 'alertas']);
});

Route::middleware(['auth', 'role:seguridad'])->prefix('seguridad')->name('seguridad.')->group(function () {    
    Route::get('/alertas', [SeguridadController::class, 'alertas'])->name('alertas');    
});


Route::post('/alerta/activar', [App\Http\Controllers\AlertaController::class, 'store'])
     ->name('alerta.activar')
     ->middleware('auth');

Route::post('/alerta/{alerta}/falsa', [\App\Http\Controllers\AlertaController::class, 'marcarFalsaAlarma'])
     ->middleware('auth')
     ->name('alerta.falsa');
     
    

 

