<?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{
    $consent=afConsentSave(
        $pdo,$uid,(int)($d['link_id']??0),is_array($d['permissions']??null)?$d['permissions']:[],!empty($d['confirm_specific'])
    );
    jsonResponse(['ok'=>true,'consent'=>afConsentApiSummary($consent),'message'=>'Consentimentos registrados. Os recursos do menor continuam protegidos.']);
}catch(Throwable $e){jsonResponse(['ok'=>false,'erro'=>$e->getMessage()],422);}
