// viewer-http.h: HTTP route setup and response helpers
//
// Registers all API routes on the httplib server.
// Uses nlohmann::json (same as llama.cpp) for metadata responses.

#pragma once

#include "viewer-model.h"

#include "httplib.h"
#include <nlohmann/json.hpp>

using json = nlohmann::json;

// register all API routes on the server
void setup_routes(httplib::Server &server, std::shared_ptr<server_state> state);

// set a JSON response on res
inline void set_json_response(httplib::Response &res, const json &body,
                              int status = 200) {
  res.status = status;
  res.set_content(body.dump(), "application/json");
}

// set a simple error JSON {"error":"message"}
inline void set_error_response(httplib::Response &res, const char *message,
                               int status) {
  json body;
  body["error"] = message;
  set_json_response(res, body, status);
}
