#pragma once
#include "Arduino.h"
#include "LittleFS.h"
#include "WiFiClientSecure.h"
#include <map>

// Global test state for inspecting behavior
extern int   g_http_get_code;
extern std::map<std::string, std::string> g_http_response_headers;
extern std::map<std::string, std::string> g_http_request_headers;
extern bool  g_http_end_called;
extern std::string g_http_body;

struct MockHTTPClient {
    bool _ended = false;

    void begin(WiFiClientSecure&, const String& url) {}

    void addHeader(const char* name, const String& value) {
        g_http_request_headers[name] = value._s;
    }

    void collectHeaders(const char** headers, int count) {}

    int GET() {
        _ended = false;
        return g_http_get_code;
    }

    String header(const char* name) {
        if (_ended) return String("");
        auto it = g_http_response_headers.find(name);
        return it != g_http_response_headers.end() ? String(it->second) : String("");
    }

    size_t writeToStream(File* f) {
        if (f && *f) {
            f->write((const uint8_t*)g_http_body.data(), g_http_body.size());
        }
        return g_http_body.size();
    }

    void end() {
        _ended = true;
        g_http_end_called = true;
    }
};
