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

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

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

Route::domain($domain)
    ->prefix($path)
    ->middleware('web')
    ->namespace('Seka\Vzdelavanie\Http\Controllers')
    ->group(function () {
        Route::get('/', 'VzdelavanieController@index')->name('vzdelavanie.index');

        Route::get('/klient', 'KlientAppController@show')->name('vzdelavanie.klient');

        Route::prefix('/kniznica')->middleware('auth')->group(function () {
            Route::prefix('/ucebny-material')->group(function () {
                Route::get('/{id}', 'UcebnicaController@show')->where('id', '[0-9]+')->middleware('can:read')->name('ucebnica.show');
                Route::get('/novy', 'UcebnicaController@create')->middleware('can:edit')->name('ucebnica.create');
                Route::post('/novy', 'UcebnicaController@store')->middleware('can:edit')->name('ucebnica.store');
                Route::get('/{id}/upravit', 'UcebnicaController@edit')->where('id', '[0-9]+')->middleware('can:edit')->name('ucebnica.edit');
                Route::put('/{id}/upravit', 'UcebnicaController@update')->where('id', '[0-9]+')->middleware('can:edit')->name('ucebnica.update');
                Route::delete('/{id}/odstranit', 'UcebnicaController@destroy')->where('id', '[0-9]+')->middleware('can:edit')->name('ucebnica.destroy');

                Route::prefix('/{id}/sekcie')->group(
                    function () {
                        Route::get('/', 'SekciaController@index')->where(['id' => '[0-9]+'])->middleware('can:read')->name('ucebnica.sekcia.index');
                        Route::get('/{sekciaId}', 'SekciaController@show')->where(['id' => '[0-9]+', 'sekciaId' => '[0-9]+'])->name('ucebnica.sekcia.show');
                        Route::get('/nova', 'SekciaController@create')->where(['id' => '[0-9]+'])->middleware('can:edit')->name('ucebnica.sekcia.create');
                        Route::post('/nova', 'SekciaController@store')->where(['id' => '[0-9]+'])->middleware('can:edit')->name('ucebnica.sekcia.store');
                        Route::get('/{sekciaId}/upravit', 'SekciaController@edit')->where(['id' => '[0-9]+', 'sekciaId' => '[0-9]+'])->middleware('can:edit')->name('ucebnica.sekcia.edit');
                        Route::put('/{sekciaId}/upravit', 'SekciaController@update')->where(['id' => '[0-9]+', 'sekciaId' => '[0-9]+'])->middleware('can:edit')->name('ucebnica.sekcia.update');
                        Route::delete('/{sekciaId}/odstranit', 'SekciaController@destroy')->where(['id' => '[0-9]+', 'sekciaId' => '[0-9]+'])->middleware('can:edit')->name('ucebnica.sekcia.destroy');
                    }
                );
            });

            Route::prefix('/kategorie')->group(
                function () {
                    Route::get('/', 'KategoriaController@index')->name('kategoria.index');
                    Route::get('/nova', 'KategoriaController@create')->middleware('can:edit')->name('kategoria.create');
                    Route::post('/nova', 'KategoriaController@store')->middleware('can:edit')->name('kategoria.store');
                    Route::get('/{kategoriaId}/upravit', 'KategoriaController@edit')->where('kategoriaId', '[0-9]+')->middleware('can:edit')->name('kategoria.edit');
                    Route::put('/{kategoriaId}/upravit', 'KategoriaController@update')->where('kategoriaId', '[0-9]+')->middleware('can:edit')->name('kategoria.update');
                    Route::delete('/{kategoriaId}/odstranit', 'KategoriaController@destroy')->where('kategoriaId', '[0-9]+')->middleware('can:edit')->name('kategoria.destroy');

                    Route::prefix('/{kategoriaId}/ucebny-material')->group(
                        function () {
                            Route::get('/', 'KategoriaUcebnicaController@index')->where('kategoriaId', '[0-9]+')->middleware('can:read')->name('kategoria.ucebnice.index');
                            Route::post('/', 'KategoriaUcebnicaController@index')->where('kategoriaId', '[0-9]+')->middleware('can:read')->name('kategoria.ucebnice.filter');
                            Route::get('/novy', 'KategoriaUcebnicaController@create')->where('kategoriaId', '[0-9]+')->middleware('can:edit')->name('kategoria.ucebnice.create');
                        }
                    );
                }
            );
        });
    }
);
