<?php
error_reporting(E_ALL);
ini_set('display_errors', 0);
header('Content-Type: application/json');

require_once 'config.php';

try {
    $db = getDB();
    $syncResult = syncNeedPointsToHouseholds($db);
    $computedScores = ensureHouseholdScoresForAllHouseholds($db);

    echo json_encode([
        'success' => true,
        'sync_result' => $syncResult,
        'computed_missing_scores' => $computedScores
    ]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'error' => $e->getMessage()
    ]);
}
