#pragma once
/* gitea_ota.h — Gitea release version checker (bd-3hte)
 *
 * WiFi task: on boot and every 30 min, queries Gitea releases API,
 * compares tag version against embedded FW_VERSION, stores update info.
 *
 * WiFi credentials read from NVS namespace "wifi" keys "ssid"/"pass".
 * Fall back to compile-time defaults if NVS is empty.
 */

#include <stdint.h>
#include <stdbool.h>

/* Gitea instance */
#define GITEA_BASE_URL      "http://gitea.vayrette.com"
#define GITEA_REPO          "seb/saltylab-firmware"
#define GITEA_API_TIMEOUT_MS 10000

/* Version check interval */
#define VERSION_CHECK_PERIOD_MS  (30u * 60u * 1000u)  /* 30 minutes */

/* Max URL/version string lengths */
#define OTA_URL_MAX     384
#define OTA_VER_MAX     32
#define OTA_SHA256_MAX  65

typedef struct {
    bool    available;
    char    version[OTA_VER_MAX];      /* remote version string, e.g. "1.2.3" */
    char    download_url[OTA_URL_MAX]; /* direct download URL for .bin */
    char    sha256[OTA_SHA256_MAX];    /* hex SHA256 (from .sha256 asset), or "" */
} ota_update_info_t;

/* Shared state — written by gitea_ota_check_task, read by display/OTA tasks */
extern ota_update_info_t g_balance_update;
extern ota_update_info_t g_io_update;

/* Initialize WiFi and start version check task */
void gitea_ota_init(void);

/* One-shot sync check (can be called from any task) */
void gitea_ota_check_now(void);
