<?php
require_once __DIR__.'/../../_bootstrap.php';
if($_SERVER['REQUEST_METHOD']!=='POST')jsonResponse(['ok'=>false,'erro'=>'Método não permitido.'],405);
afValidarCsrfApi();$u=afApiOuSessaoUsuario($pdo);$uid=(int)$u['id'];$d=requestJson();$linkId=(int)($d['link_id']??0);
try{$controls=afGuardianDashboardSaveControls($pdo,$uid,$linkId,$d);$link=afGuardianDashboardLink($pdo,$uid,$linkId);$access=afGuardianDashboardAccessDecision($pdo,(int)$link['minor_usuario_id']);jsonResponse(['ok'=>true,'controls'=>afGuardianDashboardApiControls($controls,$access)]);}catch(Throwable $e){jsonResponse(['ok'=>false,'erro'=>$e->getMessage()],422);}
