<?php
/**
 * Created by PhpStorm.
 * User: radko
 * Date: 13.11.18
 * Time: 8:11
 */

use Illuminate\Support\Facades\Route;
use Seka\Vzdelavanie\Http\Controllers\Backend\Testovanie\PouzivatelController;
use Seka\Vzdelavanie\Http\Controllers\Backend\Testovanie\TestController;
use Seka\Vzdelavanie\Http\Controllers\Backend\Testovanie\TestOtazkyController;
use Seka\Vzdelavanie\Http\Controllers\Backend\Testovanie\TestOtazkyOdpovedeController;
use Seka\Vzdelavanie\Http\Controllers\Backend\Testovanie\TestovanieController;

if ($domain = config('vzdelavanie.subdomena')) {
    $domain = sprintf(
        '%s.%s',
        $domain,
        config('app.domain')
    );
}

$path = config('vzdelavanie.cesta');

Route::domain($domain)
    ->prefix('sprava')
    ->middleware(['web', 'auth', 'permission:vzdelavanie'])
    ->name('vzdelavanie.')
    ->group(function () use ($path) {
        Route::prefix($path)
            ->name('sprava.')
            ->group(function () {
                Route::prefix('testovanie')
                    ->name('testovanie.')
                    ->group(function () {
                        Route::get('/', [TestovanieController::class, 'index'])
                            ->name('index');

                        // testy
                        Route::prefix('testy')
                            ->name('testy.')
                            ->group(function () {
                                Route::get('/', [TestController::class, 'index'])
                                    ->name('index');

                                Route::get('/novy', [TestController::class, 'create'])
                                    ->name('create');

                                Route::post('/novy', [TestController::class, 'store'])
                                    ->name('store');

                                Route::prefix('{vzdTstTstId}')
                                    ->group(function () {
                                        Route::get('/upravit', [TestController::class, 'edit'])
                                            ->name('edit');

                                        Route::put('/upravit', [TestController::class, 'update'])
                                            ->name('update');

                                        Route::delete('/odstranit', [TestController::class, 'destroy'])
                                            ->name('destroy');

                                        // otazky
                                        Route::prefix('otazky')
                                            ->name('otazky.')
                                            ->group(function () {
                                                Route::get('/', [TestOtazkyController::class, 'index'])
                                                    ->name('index');

                                                Route::get('/nova', [TestOtazkyController::class, 'create'])
                                                    ->name('create');

                                                Route::post('/nova', [TestOtazkyController::class, 'store'])
                                                    ->name('store');

                                                Route::prefix('{vzdTstOtzkId}')
                                                    ->group(function () {
                                                        Route::get('/upravit', [TestOtazkyController::class, 'edit'])
                                                            ->name('edit');

                                                        Route::put('/upravit', [TestOtazkyController::class, 'update'])
                                                            ->name('update');

                                                        Route::delete('/odstranit', [TestOtazkyController::class, 'destroy'])
                                                            ->name('destroy');

                                                        // odpovede
                                                        Route::prefix('odpovede')
                                                            ->name('odpovede.')
                                                            ->group(function () {
                                                                Route::get('/', [TestOtazkyOdpovedeController::class, 'index'])
                                                                    ->name('index');

                                                                Route::get('/nova', [TestOtazkyOdpovedeController::class, 'create'])
                                                                    ->name('create');

                                                                Route::post('/nova', [TestOtazkyOdpovedeController::class, 'store'])
                                                                    ->name('store');

                                                                Route::prefix('{vzdTstOdpvdId}')
                                                                    ->group(function () {
                                                                        Route::get('/upravit', [TestOtazkyOdpovedeController::class, 'edit'])
                                                                            ->name('edit');

                                                                        Route::put('/upravit', [TestOtazkyOdpovedeController::class, 'update'])
                                                                            ->name('update');

                                                                        Route::delete('/odstranit', [TestOtazkyOdpovedeController::class, 'destroy'])
                                                                            ->name('destroy');
                                                                    });
                                                            });
                                                    });
                                            });
                                    });
                            });

                        // pouzivatelia
                        Route::prefix('pouzivatelia')
                            ->name('pouzivatelia.')
                            ->group(function () {
                                Route::get('/', [PouzivatelController::class, 'index'])
                                    ->name('index');
                            });
                    });
            });
    });
