<?php
require_once 'config.php';
if (!isset($_SESSION['user_id'])) response(["error" => "No autorizado"], 401);

try {
    $stmt = $pdo->query("SELECT id, title, content, date, month, year, attendance_json as attendancePropertyIds, quorum_percent as quorumPercent FROM assemblies ORDER BY date DESC");
    $assemblies = $stmt->fetchAll();
    foreach($assemblies as &$a) {
        $a['attendancePropertyIds'] = json_decode($a['attendancePropertyIds'] ?? '[]');
    }
    response($assemblies);
} catch (PDOException $e) {
    response([], 200);
}
?>