Files
radiantwave/src/network/proclamation_sync.h
T

61 lines
3.0 KiB
C++

#pragma once
#include "db/database_manager.h"
#include <string>
#include <vector>
namespace radiantwave::sync {
// Parse the JSON payload returned by the proclamations endpoint.
// Strips HTML from the content body. Returns false on malformed input.
bool parseProclamationsJson(const std::string& body,
std::vector<radiantwave::db::ProclamationRecord>& out);
// Parse the JSON payload returned by the categories endpoint.
bool parseCategoriesJson(const std::string& body,
std::vector<radiantwave::db::ProclamationCategoryRecord>& out);
// Parse the JSON payload returned by the groups endpoint.
bool parseGroupsJson(const std::string& body,
std::vector<radiantwave::db::ProclamationGroupRecord>& out);
// Fetches proclamations + categories + groups from the API and stores them in
// the DB, preserving any existing selection and forcing `defaultProclamationId`
// to stay selected. Returns true only if the API sync succeeded; on failure the
// database is left untouched so the app can fall back to cached data.
//
// Also requests the user's schedule and replaces the stored schedule when the
// device has an email + license key. Schedule sync is best-effort: a schedule
// failure never fails (or rolls back) the proclamation sync.
bool syncProclamationsFromApi(radiantwave::db::DatabaseManager& db,
const std::string& defaultProclamationId);
// Fetch GET /schedule for the device's paired email + license key and replace
// the stored schedule blocks. Skips (returns false) when either credential is
// missing. Returns true only on HTTP 2xx + successful parse + successful store.
bool syncScheduleFromApi(radiantwave::db::DatabaseManager& db);
// Parse color palettes embedded in the proclamations JSON payload. Each
// proclamation object may carry a "colorPalette" array of "#RRGGBB" strings;
// the palette is keyed by the proclamation's solfeggioFrequencyId. When
// several proclamations share a frequency, the first occurrence wins. Returns
// false on malformed input.
bool parseProclamationPalettesJson(const std::string& body,
std::vector<radiantwave::db::PaletteRecord>& out);
// Fetch the standalone /color-palettes route and replace the local palette
// table (the portal is the source of truth). Returns true only on HTTP 2xx +
// successful parse + successful replace.
//
// NOTE: not yet wired into the app flow — the portal does not expose the route
// yet. Readiness code: palettes should be updated from the portal, not code
// releases, so callers should treat this as a future sync step.
bool syncColorPalettesFromApi(radiantwave::db::DatabaseManager& db);
// Alternative to syncColorPalettesFromApi: fetch proclamations and replace the
// local palette table using the palettes embedded in each proclamation.
// NOTE: not yet wired into the app flow; see syncColorPalettesFromApi.
bool syncProclamationPalettesFromApi(radiantwave::db::DatabaseManager& db);
} // namespace radiantwave::sync