<?php

use App\Http\Controllers\Auth\DenuncianteLoginController;
use App\Http\Controllers\DenunciaController;
use App\Http\Controllers\DenuncianteDashboardController;
use App\Http\Controllers\DenunciantePasswordController;
use App\Http\Controllers\PublicDenunciaController;
use App\Http\Controllers\SsoLoginController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

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

Auth::routes();

Route::get('/', [PublicDenunciaController::class, 'welcome'])->name('welcome');
Route::post('/denuncias/registrar', [PublicDenunciaController::class, 'store'])->name('denuncias.public.store');
Route::get('sso-login', [SsoLoginController::class, 'loginFromIntranet'])->name('sso.login');
Route::prefix('seguimiento')->group(function () {
    Route::get('/login', [DenuncianteLoginController::class, 'showLogin'])->name('denunciante.login');
    Route::post('/login', [DenuncianteLoginController::class, 'login'])->name('denunciante.login.post');
    Route::post('/logout', [DenuncianteLoginController::class, 'logout'])->name('denunciante.logout');

    Route::middleware(['auth', 'forzar.password'])->group(function () {
        Route::get('/cambiar-password', [DenunciantePasswordController::class, 'edit'])->name('denunciante.password.cambiar');
        Route::post('/cambiar-password', [DenunciantePasswordController::class, 'update'])->name('denunciante.password.actualizar');

        Route::get('/dashboard', [DenuncianteDashboardController::class, 'index'])->name('denunciante.dashboard')->middleware('permission:denunciante.dashboard');
        Route::get('/ver-denuncia/{denuncia}', [DenuncianteDashboardController::class, 'show'])->name('denunciante.denuncias.show')->middleware('permission:denunciante.denuncias.show');
    });
});

Route::middleware(['auth'])->group(function(){
    Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home')->middleware('permission:home');
    //Roles
    Route::post('roles/store',[App\Http\Controllers\RoleController::class,'store'])->name('roles.store')->middleware('permission:roles.create');
    Route::get('roles',[App\Http\Controllers\RoleController::class,'index'])->name('roles.index')->middleware('permission:roles.index');
    Route::get('roles/create',[App\Http\Controllers\RoleController::class,'create'])->name('roles.create')->middleware('permission:roles.create');
    Route::put('roles/{role}',[App\Http\Controllers\RoleController::class,'update'])->name('roles.update')->middleware('permission:roles.edit');
    Route::get('roles/{role}',[App\Http\Controllers\RoleController::class,'show'])->name('roles.show')->middleware('permission:roles.show');
    Route::delete('roles/{role}',[App\Http\Controllers\RoleController::class,'destroy'])->name('roles.destroy')->middleware('permission:roles.destroy');
    Route::get('roles/{role}/edit',[App\Http\Controllers\RoleController::class,'edit'])->name('roles.edit')->middleware('permission:roles.edit');
    
    //User
    Route::post('users/store',[App\Http\Controllers\UserController::class,'store'])->name('users.store')->middleware('permission:users.create');
    Route::get('users',[App\Http\Controllers\UserController::class,'index'])->name('users.index')->middleware('permission:users.index');
    Route::get('users/create',[App\Http\Controllers\UserController::class,'create'])->name('users.create')->middleware('permission:users.create');
    Route::put('users/{user}',[App\Http\Controllers\UserController::class,'update'])->name('users.update')->middleware('permission:users.edit');
    Route::delete('users/{user}',[App\Http\Controllers\UserController::class,'destroy'])->name('users.destroy')->middleware('permission:users.destroy');
    Route::get('users/{user}',[App\Http\Controllers\UserController::class,'edit'])->name('users.edit')->middleware('permission:users.edit');
    
    Route::get('datos_empleado',[App\Http\Controllers\UserController::class,'datos_empleado'])->name('datos_empleado');

    Route::get('/denuncias', [App\Http\Controllers\DenunciaController::class, 'index'])
        ->name('denuncias.index')->middleware('permission:denuncias.index');

    Route::get('/denuncias/finalizadas', [App\Http\Controllers\DenunciaController::class, 'finalizadas'])
        ->name('denuncias.finalizadas')->middleware('permission:denuncias.finalizadas');

    Route::get('/denuncias/{denuncia}', [App\Http\Controllers\DenunciaController::class, 'show'])
        ->name('denuncias.show')->middleware('permission:denuncias.show');

    Route::post('/denuncias/{denuncia}/seguimiento', [App\Http\Controllers\DenunciaSeguimientoController::class, 'store'])
        ->name('denuncias.seguimiento.store')->middleware('permission:denuncias.seguimiento.create');

    Route::get('/denuncias-reporte/pdf', [App\Http\Controllers\ReporteDenunciaController::class, 'pdf'])
        ->name('denuncias.reporte.pdf')->middleware('permission:denuncias.reporte.pdf');
});