<?php

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

use App\Http\Controllers\API\BaseController;
use App\Notifications\Push\MAAISEKUserNotificationsCountPushNotification;
use Dingo\Api\Http\Response;

/**
 * Class MarkAllAsReadAction
 */
final class MarkAllAsReadAction extends BaseController
{
    public function __invoke(): Response
    {
        $pouzivatel = $this->auth->user();
        $pouzivatel->unreadNotifications()->each(function ($notification) {
            $notification->markAsRead();
        });
        $pouzivatel->notify(new MAAISEKUserNotificationsCountPushNotification);

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