<?php

use Illuminate\Support\Facades\Route;

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

Auth::routes();

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

Route::middleware('auth')->group(function () {
    Route::get('/dashboard', [App\Http\Controllers\HomeController::class, 'dashboard'])->name('dashboard');

    Route::resource('users', App\Http\Controllers\UserController::class)->only(['index', 'create', 'store']);

    Route::resource('unit-types', App\Http\Controllers\UnitTypeController::class);
    Route::post('organizational-units/{organizationalUnit}/questionnaire', [App\Http\Controllers\QuestionnaireController::class, 'submitForUnit'])
        ->name('organizational-units.questionnaire.submit');
    Route::resource('organizational-units', App\Http\Controllers\OrganizationalUnitController::class);

    Route::resource('question-types', App\Http\Controllers\QuestionTypeController::class)
        ->only(['index', 'create', 'store']);

    Route::get('/questionnaire', [App\Http\Controllers\QuestionnaireController::class, 'form'])
        ->name('questionnaire.form');
    Route::post('/questionnaire/unit', [App\Http\Controllers\QuestionnaireController::class, 'storeQuestionnaireUnit'])
        ->name('questionnaire.unit.store');
    Route::post('/questionnaire/unit/clear', [App\Http\Controllers\QuestionnaireController::class, 'clearQuestionnaireUnit'])
        ->name('questionnaire.unit.clear');
    Route::post('/questionnaire', [App\Http\Controllers\QuestionnaireController::class, 'submit'])
        ->name('questionnaire.submit');
    Route::get('/questionnaire/results', [App\Http\Controllers\QuestionnaireController::class, 'results'])
        ->name('questionnaire.results');

    Route::get('/questions', [App\Http\Controllers\QuestionnaireController::class, 'index'])
        ->name('questions.index');
    Route::get('/questions/create', [App\Http\Controllers\QuestionnaireController::class, 'createQuestionForm'])
        ->name('questions.create');
    Route::post('/questions', [App\Http\Controllers\QuestionnaireController::class, 'storeQuestion'])
        ->name('questions.store');
    Route::get('/questions/{question}/edit', [App\Http\Controllers\QuestionnaireController::class, 'editQuestion'])
        ->name('questions.edit');
    Route::put('/questions/{question}', [App\Http\Controllers\QuestionnaireController::class, 'updateQuestion'])
        ->name('questions.update');
    Route::delete('/questions/{question}', [App\Http\Controllers\QuestionnaireController::class, 'destroyQuestion'])
        ->name('questions.destroy');
    Route::post('/answers', [App\Http\Controllers\QuestionnaireController::class, 'storeAnswer'])
        ->name('answers.store');
    Route::get('/questions/{question}/answers', [App\Http\Controllers\QuestionnaireController::class, 'questionAnswers'])
        ->name('questions.answers.index');
});
