<?php
require_once __DIR__ . '/../_bootstrap.php';
require_once ROOT_PATH . '/includes/match_functions.php';

$rows = $pdo->query('SELECT chave,valor,tipo FROM af_configuracoes WHERE publica=1')->fetchAll();
$out = [];
foreach ($rows as $r) {
    $out[$r['chave']] = match ($r['tipo']) {
        'int' => (int)$r['valor'],
        'float' => (float)$r['valor'],
        'bool' => filter_var($r['valor'], FILTER_VALIDATE_BOOLEAN),
        'json' => json_decode($r['valor'], true),
        default => $r['valor'],
    };
}
$out['api_version'] = '21.0';
$out['viral_version'] = defined('VIRAL_VERSION') ? VIRAL_VERSION : '11.0';
$out['admin_version'] = defined('ADMIN_VERSION') ? ADMIN_VERSION : '13.0';
$out['age_protection_version'] = defined('AGE_PROTECTION_VERSION') ? AGE_PROTECTION_VERSION : '14.0';
$out['minor_policy_version'] = defined('MINOR_POLICY_VERSION') ? MINOR_POLICY_VERSION : '18.0';
$out['safe_camera_version'] = defined('SAFE_CAMERA_VERSION') ? SAFE_CAMERA_VERSION : '19.0';
$out['guardian_dashboard_version'] = defined('GUARDIAN_DASHBOARD_VERSION') ? GUARDIAN_DASHBOARD_VERSION : '20.0';
$out['privacy_center_version'] = defined('PRIVACY_CENTER_VERSION') ? PRIVACY_CENTER_VERSION : '21.0';
$out['legal_versions'] = ['terms'=>TERMS_VERSION,'privacy'=>PRIVACY_POLICY_VERSION,'child_privacy'=>CHILD_PRIVACY_VERSION,'cookies'=>COOKIE_NOTICE_VERSION];
$out['parental_consent_version'] = defined('PARENTAL_CONSENT_VERSION') ? PARENTAL_CONSENT_VERSION : '17.0';
$out['age_policy'] = ['adult_age'=>18,'minor_policy_engine'=>true,'minor_safe_camera_ready'=>(bool)afMinorPolicyConfig($pdo,'minor_safe_camera_ready',false),'minor_safe_camera_video_upload'=>false,'minor_safe_camera_webrtc'=>false,'minor_safe_camera_person_limit'=>(int)afMinorPolicyConfig($pdo,'minor_safe_camera_person_limit',1),'under_13_controlled_event_only'=>true,'high_risk_features_locked'=>true,'guardian_parental_controls'=>true];
$out['webrtc_enabled'] = WEBRTC_ENABLED;
$out['webrtc_ice_servers'] = afWebRtcIceServers();
$out['webrtc_max_viewers'] = WEBRTC_MAX_VIEWERS;
jsonResponse(['ok' => true, 'configuracoes' => $out]);
