// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3
//
// Shared libcurl download primitives for the in-app updaters (miner + daemon). Both the
// XmrigUpdater and DaemonUpdater workers issued byte-identical libcurl GET/download code —
// including the security-critical TLS-verify and max-body-size options. Sharing it here means
// those options are defined exactly once, so a curl/TLS change can't silently drift between the
// two signature-verified download-and-execute paths. The header stays curl-free (callers that
// only download don't need <curl/curl.h>).

#pragma once

#include <functional>
#include <string>

namespace dragonx {
namespace util {

// GET `url` over TLS (peer + host verified) into a string. Follows redirects; 30s transfer /
// 15s connect timeout; browser-agnostic User-Agent. Returns "" on ANY failure (curl error or
// non-2xx status). `logTag` (e.g. "[xmrig-updater]") prefixes the debug log on failure.
std::string httpGetString(const std::string& url, const char* logTag);

// Download `url` over TLS (peer + host verified) to `destPath`, refusing bodies larger than
// `maxBytes` (a defense ahead of the checksum/signature check). `onProgress(downloaded, total)`
// is invoked live during the transfer; returning false aborts it (used for cancellation). On
// any failure the partial file is removed and false is returned. `logTag` prefixes debug logs.
bool httpDownloadToFile(const std::string& url, const std::string& destPath,
                        const char* logTag, long long maxBytes,
                        const std::function<bool(double downloaded, double total)>& onProgress);

} // namespace util
} // namespace dragonx
