<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\IssueController;
use App\Http\Controllers\ConfigController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\PermissionController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return redirect()->route('dashboard');
});


Route::middleware(['auth', 'verified'])->group(function () {
  Route::get('/dashboard', function () {
    return view('dashboard');
  })->name('dashboard');

  Route::resource('user', UserController::class, ['only' => ['index', 'store']]);
  Route::get('user/progetti', [UserController::class, 'load_progetti'])->name('user.progetti');
  Route::post('user/progetti', [UserController::class, 'update_progetti'])->name('user.progetti');
  Route::get('user/roles', [UserController::class, 'roles'])->name('user.roles');
  Route::post('user/updateRole', [UserController::class, 'updateRole'])->name('user.updateRole');

  Route::get('issue', [IssueController::class, 'index'])->name('issue.index');
  Route::get('issue/show', [IssueController::class, 'show'])->name('issue.show');
  Route::get('issue/load_custom_fields', [IssueController::class, 'load_custom_fields'])->name('issue.load_custom_fields');
  Route::get('issue/nuovo', [IssueController::class, 'nuovo'])->name('issue.nuovo');
  Route::post('issue/crea', [IssueController::class, 'crea'])->name('issue.crea');
  Route::get('attachment/{id?}/download', [IssueController::class, 'download'])->name('attachment.download');

  Route::get('issue/user_report', [IssueController::class, 'show_user_report'])->name('issue.user_report');
  Route::post('issue/user_report', [IssueController::class, 'user_report'])->name('issue.user_report');

  Route::get('issue/admin_report', [IssueController::class, 'show_admin_report'])->name('issue.admin_report');
  Route::post('issue/admin_report', [IssueController::class, 'admin_report'])->name('issue.admin_report');

  Route::get('config', [ConfigController::class, 'index'])->name('config.index');
  Route::post('save', [ConfigController::class, 'save'])->name('config.save');

  // Ruoli
  Route::resource('roles', RoleController::class, ['only' => ['index', 'store']]);
  Route::resource('permissions', PermissionController::class, ['only' => ['index', 'store']]);
  Route::post('roles/updatePermission', [RoleController::class, 'updatePermission'])->name('roles.updatePermission');
  Route::get('roles/user', [RoleController::class, 'role_user'])->name('roles.user');
  Route::post('roles/rimuovi_utente', [RoleController::class, 'rimuovi_utente'])->name('roles.rimuovi_utente');
});

require __DIR__.'/auth.php';
