<?php
declare(strict_types=1);
require_once __DIR__.'/../../authentication/api/connect.php';
function suggestion_name_sql(): string {return "COALESCE(CASE WHEN LOWER(TRIM(COALESCE(u.full_name,''))) IN ('','null','undefined') THEN NULL ELSE u.full_name END,u.username)";}
function suggestion_categories(): array {return ['learning','facilities','software','student_life','other'];}
function suggestion_can_remove(array $user,int $author): bool {return (int)$user['id']===$author||in_array($user['role'],['admin','staff'],true);}
function suggestion_post(int $id,bool $lock=false): array {
 $q=db()->prepare('SELECT * FROM suggestions WHERE id=? AND deleted_at IS NULL'.($lock?' FOR UPDATE':''));$q->execute([$id]);$post=$q->fetch();if(!$post)reply(404,['message'=>'This suggestion is no longer available.']);return $post;
}
