<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\IssueController;
use App\Http\Controllers\AziendaController;
use App\Http\Controllers\ConfigController;
use App\Http\Controllers\UserController;

/*
|--------------------------------------------------------------------------
| 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('login');
});


Route::get('login', [LoginController::class, 'index'])->name('login');
Route::post('login', [LoginController::class, 'login'])->name('login');
Route::post('logout', [LoginController::class, 'logout'])->name('logout');


Route::middleware(['redmine_auth'])->group(function () {
  Route::get('home', [HomeController::class, 'home'])->name('home');
  Route::get('issue', [IssueController::class, 'index'])->name('issue.index');
  Route::get('issue/show', [IssueController::class, 'show'])->name('issue.show');
  Route::get('issue/{id}/firma', [IssueController::class, 'firma'])->name('issue.firma');
  Route::post('issue/firma_rapporto', [IssueController::class, 'firma_rapporto'])->name('issue.firma_rapporto');
  Route::get('issue/success', [IssueController::class, 'success'])->name('issue.success');

  Route::resource('azienda', AziendaController::class, ['only' => ['index', 'store']]);

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

  // Profilo
  Route::get('profilo', [UserController::class, 'profilo'])->name('user.profilo');
  Route::post('profilo', [UserController::class, 'salva_profilo'])->name('user.profilo');
});
