#ifndef TRANSTUI_HTTP_H
#define TRANSTUI_HTTP_H

#include <stddef.h>

typedef struct {
    int status;
    char *body;
    size_t body_len;
    char session_id[128]; /* set if response carried X-Transmission-Session-Id */
} HttpResponse;

/* Issues a single HTTP/1.1 POST request with a JSON body and reads the full
 * response. resp is always initialized on return; check resp->status.
 * Returns 0 if the request/response was exchanged (regardless of HTTP status),
 * -1 on a network-level failure (err filled with a message). */
int http_post_json(const char *host, int port, const char *path,
                    const char *user, const char *pass,
                    const char *session_id_in,
                    const char *body, size_t body_len,
                    HttpResponse *resp, char *err, size_t errlen);

void http_response_free(HttpResponse *resp);

#endif
