<?php
require_once __DIR__.'/../app/bootstrap.php';
use App\Core\Auth;use App\Core\Database;use App\Core\Response;
Auth::requireLogin('public/login.php');if($_SERVER['REQUEST_METHOD']!=='POST'||!verify_csrf())Response::json(['ok'=>false,'message'=>'Invalid request.'],419);$d=request_data();
if(!empty($d['all']))Database::execute('UPDATE notifications SET read_at=NOW() WHERE user_id=? AND read_at IS NULL',[Auth::id()]);else Database::execute('UPDATE notifications SET read_at=NOW() WHERE id=? AND user_id=?',[(int)($d['id']??0),Auth::id()]);
Response::json(['ok'=>true,'unread'=>db_count('notifications','user_id=? AND read_at IS NULL',[Auth::id()])]);
