<?php

declare(strict_types=1);

namespace App\Http\Controllers\API\V1\Pouzivatel\PushNotifications\Frontend;

use Dingo\Api\Http\Response;
use App\Http\Controllers\API\BaseController;
use App\Http\Requests\StoreUserNotificationTokenRequest;
use App\Services\PushNotificationsService\PushNotificationsServiceContract;

/**
 * Class StoreUsersPushNotificationTokenAction
 *
 * @package App\Http\Controllers\API\V1\Pouzivatel\PushNotifications\Frontend
 */
final class StoreUsersPushNotificationTokenAction extends BaseController
{
    /**
     * @param \App\Http\Requests\StoreUserNotificationTokenRequest                    $request
     * @param \App\Services\PushNotificationsService\PushNotificationsServiceContract $pushNotificationsService
     *
     * @return \Dingo\Api\Http\Response
     */
    public function __invoke(StoreUserNotificationTokenRequest $request, PushNotificationsServiceContract $pushNotificationsService): Response
    {
        /** @var \App\Models\Pouzivatel\Pouzivatel $user */
        $user = $request->user();
        $token = $request->request->get('notification_token');

        $pushNotificationsService->storeUserDeviceToken($user, $token);

        return $this->response()->created();
    }
}
