<?php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../config/auth.php';
requireRole([1, 5]);
$db = getDB();
$q  = post('q','');
$limit = min((int)post('limit',10), 20);
$stmt = $db->prepare("SELECT id, username, full_name, role_id FROM users WHERE is_active=1 AND (username LIKE ? OR full_name LIKE ?) ORDER BY full_name LIMIT $limit");
$stmt->execute(["%$q%", "%$q%"]);
apiSuccess(['users' => $stmt->fetchAll()]);
