<?php
namespace App\Controllers;

require_once BASE_PATH . '/app/helpers/permissions.php';

require_once BASE_PATH . '/app/helpers/conference_scope.php';

use App\Core\NotificationService;

class NotificationCountController
{
    private function startSession(): void
    {
        if (session_status() !== PHP_SESSION_ACTIVE) {
            session_start();
        }
    }

    public function index()
    {
$this->startSession();

        header('Content-Type: application/json; charset=utf-8');

        if (empty($_SESSION['user_id'])) {
            echo json_encode(['ok' => false, 'count' => 0]);
            return;
        }

        $svc = new NotificationService();

        echo json_encode([
            'ok' => true,
            'count' => $svc->unreadCount(
                (int)$_SESSION['user_id'],
                !empty($_SESSION['conference_id']) ? (int)$_SESSION['conference_id'] : null
            )
        ]);
    }
}
