<?php
require_once __DIR__.'/../../_bootstrap.php';$u=apiUsuario($pdo);$uid=(int)$u['id'];
afSyncLegalDocuments($pdo);$required=afRequiredLegalDocuments($pdo,$uid);$missing=afMissingLegalAcceptances($pdo,$uid);$accepted=[];
if(afPrivacyTableExists($pdo,'af_legal_acceptances')){$st=$pdo->prepare("SELECT a.accepted_at,a.source,d.id document_id,d.document_key,d.version_key,d.title,d.content_hash FROM af_legal_acceptances a JOIN af_legal_documents d ON d.id=a.legal_document_id WHERE a.user_id=? ORDER BY a.id DESC");$st->execute([$uid]);$accepted=$st->fetchAll()?:[];}
jsonResponse(['ok'=>true,'privacy_center_version'=>PRIVACY_CENTER_VERSION,'requires_acceptance'=>(bool)$missing,'required_documents'=>array_map(static fn(array $d):array=>['id'=>(int)$d['id'],'key'=>$d['document_key'],'version'=>$d['version_key'],'title'=>$d['title'],'summary'=>$d['summary']],$required),'missing_documents'=>array_map(static fn(array $d):array=>['id'=>(int)$d['id'],'key'=>$d['document_key'],'version'=>$d['version_key'],'title'=>$d['title']],$missing),'accepted_documents'=>$accepted,'subjects'=>afPrivacySubjects($pdo,$uid)]);
