<?php

declare(strict_types=1);

namespace App\Controller;

use App\Entity\User;
use App\Repository\NotificationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

class MarkAllReadController extends AbstractController
{
    public function __construct(
        private readonly NotificationRepository $notificationRepository,
    ) {}

    #[Route('/api/notifications/mark-all-read', name: 'notification_mark_all_read', methods: ['POST'], priority: 1)]
    #[IsGranted('IS_AUTHENTICATED_FULLY')]
    public function __invoke(): Response
    {
        /** @var User $user */
        $user = $this->getUser();

        $this->notificationRepository->markAllReadByUser($user);

        return new Response(null, Response::HTTP_NO_CONTENT);
    }
}
