<?php

declare(strict_types=1);

namespace App\Module\Core\Infrastructure\Controller;

use App\Module\Core\Infrastructure\Doctrine\DoctrineNotificationRepository;
use App\Shared\Domain\Contract\UserInterface;
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 DoctrineNotificationRepository $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 UserInterface $user */
        $user = $this->getUser();

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

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