<?php
require_once __DIR__.'/../../_bootstrap.php';
$u=apiUsuario($pdo);$uid=(int)$u['id'];
if(!afGuardianUsuarioPodeSerResponsavel($pdo,$uid))jsonResponse(['ok'=>false,'erro'=>'Conta não autorizada como responsável.'],403);
$verification=afGuardianVerificationStatus($pdo,$uid);unset($verification['row']);
$dependents=[];
foreach(afGuardianDependentes($pdo,$uid) as $d){
    $controls=afGuardianDashboardEnsureControls($pdo,$uid,(int)$d['id']);
    $access=afGuardianDashboardAccessDecision($pdo,(int)$d['minor_usuario_id']);
    $dependents[]=['link_id'=>(int)$d['id'],'minor_user_id'=>(int)$d['minor_usuario_id'],'name'=>$d['nome'],'username'=>$d['username'],'aura_id'=>$d['aura_id'],'age'=>(int)$d['idade_declarada'],'relationship'=>$d['parentesco'],'controls'=>afGuardianDashboardApiControls($controls,$access),'stats'=>afGuardianDashboardStats($pdo,(int)$d['minor_usuario_id'])];
}
jsonResponse(['ok'=>true,'verification'=>$verification,'unread_alerts'=>count(afGuardianDashboardAlerts($pdo,$uid,100,true)),'dependents'=>$dependents]);
