<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\AdminBundle\Controller;

use Ferienpass\CoreBundle\Entity\User;
use Ferienpass\CoreBundle\Repository\ActivityNotificationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;

/**
 * Per-user side-channel for the admin lists: returns the base58 uuids of the
 * subjects the current colleague has unread activity on. The lists themselves
 * are cached by user-context-hash bucket (shared across same-role admins), so
 * this individual-user state must NOT be baked into them — it is served
 * `private, no-store` and applied client-side (see the `activity_unread`
 * Stimulus controller).
 */
#[Route('/_activity-unread', name: 'admin_activity_unread', methods: ['GET'])]
final class ActivityUnreadController extends AbstractController
{
    public function __invoke(ActivityNotificationRepository $notifications): JsonResponse
    {
        $user = $this->getUser();
        $items = $user instanceof User ? $notifications->findUnreadSubjectUuids($user) : [];

        $response = new JsonResponse(['items' => $items]);
        $response->setPrivate();
        $response->headers->set('Cache-Control', 'private, no-store, max-age=0');

        return $response;
    }
}
