<?php
require_once __DIR__.'/../../_bootstrap.php';
$u=apiUsuario($pdo);$uid=(int)$u['id'];
if($_SERVER['REQUEST_METHOD']!=='POST')jsonResponse(['ok'=>false,'erro'=>'Método não permitido.'],405);
$d=requestJson();
try{
    $r=afGuardianCriarConvite($pdo,$uid,(string)($d['nome']??''),(string)($d['email']??''),(string)($d['telefone']??''),(string)($d['parentesco']??'responsavel'));
    jsonResponse(['ok'=>true,'convite'=>['id'=>$r['id'],'expira_horas'=>$r['expira_horas'],'email_enviado'=>$r['email_enviado'],'link'=>$r['link']]],201);
}catch(Throwable $e){jsonResponse(['ok'=>false,'erro'=>$e->getMessage()],422);}
