<?php
session_start();
require 'conexao.php';

if (!isset($_SESSION['logado']) || $_SESSION['logado'] !== true) {
    http_response_code(401);
    echo json_encode([]);
    exit;
}

$tenant_id = $_SESSION['tenant_id'];
$usuario_id = $_SESSION['id'];

$stmt = $pdo->prepare('SELECT id, nome FROM usuarios WHERE tenant_id = ? AND ativo = "sim" AND id != ?');
$stmt->execute([$tenant_id, $usuario_id]);
$usuarios = $stmt->fetchAll(PDO::FETCH_ASSOC);

header('Content-Type: application/json');
echo json_encode($usuarios);
