<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie;

use Closure;
use Illuminate\Support\Facades\Route;
use Elceka\Laravel\HashId\Facades\Hasher;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

/**
 * Class RouteServiceProvider
 *
 * @package Seka\Vzdelavanie
 */
final class RouteServiceProvider extends ServiceProvider
{
    /**
     *
     */
    public function boot(): void
    {
        parent::boot();

        Route::bind('vzdKnzncUcbnMtrlId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdKnzncSekciaId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdKnzncKategoriaId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdKnzncOtazkaId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdKnzncOdpovedId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdTstTstId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdTstOtzkId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdTstOdpvdId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdPzvtlKnzncOblbnId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdPzvtlTstTstId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdPzvtlTstOtzkId', function ($id) {
            return Hasher::decode($id);
        });

        Route::bind('vzdPzvtlTstOdpvdId', function ($id) {
            return Hasher::decode($id);
        });

        $this->routes(function () {
            $this->mapWebRoutes();
        });
    }

    /**
     *
     */
    protected function mapWebRoutes(): void
    {
        // BACKEND
        Route::middleware('web')
            ->group(__DIR__ . '/../routes/backend/web.php');
        Route::middleware('web')
            ->group(__DIR__ . '/../routes/backend/testy/web.php');
        Route::middleware('web')
            ->group(__DIR__ . '/../routes/backend/kniznica/web.php');
        Route::prefix('')
            ->group(__DIR__ . '/../routes/backend/kniznica/api.php');

        // FRONTEND
        Route::middleware('web')
            ->group(__DIR__ . '/../routes/frontend/web.php');
        Route::middleware('web')
            ->group(__DIR__ . '/../routes/frontend/testy/web.php');
        Route::middleware('web')
            ->group(__DIR__ . '/../routes/frontend/kniznica/web.php');
        Route::prefix('')
            ->group(__DIR__ . '/../routes/frontend/kniznica/api.php');
    }
}
