<?php

use App\Http\Controllers\API\V1\Auth\LoginAction;
use App\Http\Controllers\API\V1\Auth\LogoutAction;
use App\Http\Controllers\API\V1\Auth\MeAction;
use App\Http\Controllers\API\V1\Auth\RefreshAction;
use App\Http\Controllers\API\V1\Informacia\Frontend\OhodnotInformaciuAction;
use App\Http\Controllers\API\V1\Informacia\Frontend\ZiskatInformaciuAction;
use App\Http\Controllers\API\V1\Informacia\Frontend\ZiskatVsetkyHodnoteniaInformacieAction;
use App\Http\Controllers\API\V1\Informacia\Frontend\ZiskatZoznamInformaciiAction;
use App\Http\Controllers\API\V1\Pouzivatel\Notifications\Frontend\GetAction;
use App\Http\Controllers\API\V1\Pouzivatel\Notifications\Frontend\ListAction;
use App\Http\Controllers\API\V1\Pouzivatel\Notifications\Frontend\MarkAllAsReadAction;
use App\Http\Controllers\API\V1\Pouzivatel\Notifications\Frontend\MarkAsUnreadAction;
use App\Http\Controllers\API\V1\Pouzivatel\PushNotifications\Frontend\StoreUsersPushNotificationTokenAction;
use Dingo\Api\Facade\API;
use Dingo\Api\Routing\Router;

$api = API::router();
$routeName = 'app.api.frontend.pouzivatelia';

$api->version('v1', ['middleware' => 'api', 'limit' => 60, 'expires' => 1,], function (Router $api) {
    $api->group([
        'prefix' => 'auth',
    ], function (Router $api) {
        $api->post('/login', LoginAction::class);
    });
});
$api->version('v1', ['middleware' => 'api_v1', 'limit' => 60, 'expires' => 1,], function (Router $api) {
    $api->group([
        'prefix' => 'auth',
    ], function (Router $api) {
        $api->get('/logout', LogoutAction::class);
        $api->get('/me', MeAction::class);
        $api->get('/refresh', RefreshAction::class);
    });
});

$api->version(
    'v1',
    ['middleware' => ['api_v1', 'role:admin|technik|spravca_pek|prijem',], 'limit' => 120, 'expires' => 1,],
    function ($api) use ($routeName) {
        $api->group([
            'prefix' => 'pouzivatelia',
        ], function ($api) use ($routeName) {
            $api->group([
                'prefix' => 'push-notifikacie',
            ], function ($api) use ($routeName) {
                $api->post(
                    '/token',
                    [
                        'as' => "{$routeName}.push_notifications.token.create",
                        'uses' => StoreUsersPushNotificationTokenAction::class,
                    ],
                );
            });

            $api->group([
                'prefix' => 'notifikacie',
            ], function ($api) use ($routeName) {
                $api->get(
                    '/',
                    [
                        'as' => "{$routeName}.notifications.list",
                        'uses' => ListAction::class,
                    ],
                );
                $api->get(
                    '/{uuid}',
                    [
                        'as' => "{$routeName}.notifications.get",
                        'uses' => GetAction::class,
                    ],
                );
                $api->patch(
                    '/',
                    [
                        'as' => "{$routeName}.notifications.markAllAsRead",
                        'uses' => MarkAllAsReadAction::class,
                    ],
                );
                $api->patch(
                    '/{uuid}',
                    [
                        'as' => "{$routeName}.notifications.markAsUnread",
                        'uses' => MarkAsUnreadAction::class,
                    ],
                );
            });
        });
    },
);

$api->version(
    'v1',
    ['middleware' => 'api_v1', 'limit' => 120, 'expires' => 1,],
    function ($api) {
        $routeName = 'app.api.frontend';

        $api->group([
            'prefix' => 'informacie',
        ], function ($api) use ($routeName) {
            $api->get(
                '/',
                [
                    'as' => "{$routeName}.informacie.index",
                    'uses' => ZiskatZoznamInformaciiAction::class,
                ],
            );
            $api->get(
                '/{informaciaHashId}',
                [
                    'as' => "{$routeName}.informacie.get",
                    'uses' => ZiskatInformaciuAction::class,
                ],
            );
            $api->get(
                '/{informaciaHashId}/hodnotenia',
                [
                    'as' => "{$routeName}.informacie.hodnotenia.get",
                    'uses' => ZiskatVsetkyHodnoteniaInformacieAction::class,
                ],
            );
            $api->patch(
                '/{informaciaHashId}/hodnotenia',
                [
                    'as' => "{$routeName}.informacie.hodnotenie.patch",
                    'uses' => OhodnotInformaciuAction::class,
                ],
            );
        });
    },
);
