<?php
require_once APP_PATH . '/Core/BaseController.php';
require_once APP_PATH . '/Models/Notification.php';
require_once APP_PATH . '/Core/CSRF.php';

class NotificationController extends BaseController {

    private Notification $notifModel;

    public function __construct() {
        $this->notifModel = new Notification();
    }

    public function index(): void {
        $notifications = $this->notifModel->getForUser(Auth::id(), 50);
        $this->notifModel->markAllRead(Auth::id());
        $this->view('notifications.index', [
            'title'         => 'Notifications — BOAFO',
            'notifications' => $notifications,
        ]);
    }

    public function markRead(string $id): void {
        $this->notifModel->markRead((int)$id, Auth::id());
        $this->json(['success'=>true]);
    }

    public function count(): void {
        $this->json(['count'=>$this->notifModel->unreadCount(Auth::id())]);
    }
}
