<?php

namespace App\Controllers;

use App\Services\NotificationService;

class NotificationController extends BaseController
{
    public function __construct() {
        if (session_status() === PHP_SESSION_NONE) {
            session_start();
        }
    }

    public function getNotifications()
    {
        header('Content-Type: application/json');

        $notifications = NotificationService::getNotifications();
        echo json_encode($notifications);
        exit;
    }

    public function clearNotifications()
    {
        $user_id = $_SESSION['user_id'] ?? null;

        if (!$user_id) {
            echo json_encode(['success' => false, 'message' => 'Usuario no autenticado']);
            return;
        }

        $success = NotificationService::markNotificationsAsReadByUser($user_id);
        echo json_encode(['success' => $success]);
    }

}