<?php
declare(strict_types=1);

require_once __DIR__ . '/../../system/bootstrap.php';
require_once __DIR__ . '/../../system/auth.php';
require_once __DIR__ . '/../../system/response.php';

header('Content-Type: application/json');

/* =========================
   AUTH
   ========================= */

$user = require_auth($pdo);

/* =========================
   FETCH HIERARCHY
   ========================= */

$sql = "
SELECT 
    id,
    role_key AS role,
    shiftboss_id,
    manager_id
FROM users
WHERE active = 1
AND company_id = :company_id
";

$stmt = $pdo->prepare($sql);

$stmt->execute([
    'company_id' => $user['company_id']
]);

$users = $stmt->fetchAll(PDO::FETCH_ASSOC);

/* =========================
   RESPONSE
   ========================= */

success("Hierarchy loaded", [
    'users' => $users
]);