<?php
require_once __DIR__.'/../../_bootstrap.php';
$u=apiUsuario($pdo);$uid=(int)$u['id'];
if($_SERVER['REQUEST_METHOD']!=='GET')jsonResponse(['ok'=>false,'erro'=>'Método não permitido.'],405);
$linkId=(int)($_GET['link_id']??0);
if($linkId<=0)jsonResponse(['ok'=>false,'erro'=>'Informe o vínculo do dependente.'],422);
$st=$pdo->prepare("SELECT l.minor_usuario_id,m.nome,m.username,m.aura_id FROM af_guardian_minor_links l JOIN af_usuarios m ON m.id=l.minor_usuario_id WHERE l.id=? AND l.guardian_usuario_id=? AND l.status IN ('pending_verification','verified_pending_consent','active') LIMIT 1");
$st->execute([$linkId,$uid]);$link=$st->fetch();
if(!$link)jsonResponse(['ok'=>false,'erro'=>'Dependente não encontrado.'],404);
$summary=afMinorPolicySummary($pdo,(int)$link['minor_usuario_id'],true);
jsonResponse(['ok'=>true,'dependent'=>['name'=>$link['nome'],'username'=>$link['username'],'aura_id'=>$link['aura_id']],'policy'=>afMinorPolicyApiSummary($summary)]);
