<?php
require_once 'config.php';

checkAccess(['admin', 'programmer', 'board']);

$data = json_decode(file_get_contents("php://input"), true);

if (!isset($data['title']) || !isset($data['content'])) {
    response(["error" => "Datos de acta incompletos"], 400);
}

try {
    $stmt = $pdo->prepare("INSERT INTO assemblies 
        (title, content, date, month, year, attendance_json, quorum_percent) 
        VALUES (?, ?, ?, ?, ?, ?, ?)");
    $stmt->execute([
        $data['title'],
        $data['content'],
        $data['date'] ?? date('Y-m-d'),
        $data['month'],
        $data['year'],
        json_encode($data['attendancePropertyIds'] ?? []),
        $data['quorumPercent'] ?? 0
    ]);
    response(["success" => true]);
} catch (PDOException $e) {
    response(["error" => "Error al guardar acta: " . $e->getMessage()], 500);
}
?>