#ifndef PFC_UI_ERRORS_HPP
#define PFC_UI_ERRORS_HPP
#include <nlohmann/json.hpp>
#include <sstream>
#include <string>
#include <vector>
namespace pfc {
namespace ui {
inline std::string
format_config_error(
const std::string &field_name,
const std::string &description,
const std::string &expected_type,
const std::string &actual_value,
const std::vector<std::string> &valid_options = {},
const std::string &example = "") {
std::ostringstream oss;
oss << "Invalid configuration: Field '" << field_name << "' ";
if (actual_value == "missing") {
oss << "is missing.\n";
} else {
oss << "has invalid value.\n";
}
oss << " Description: " << description << "\n";
oss << " Expected: " << expected_type << "\n";
oss << " Got: " << actual_value << "\n";
if (!valid_options.empty()) {
oss << " Valid options: ";
for (size_t i = 0; i < valid_options.size(); ++i) {
oss << "'" << valid_options[i] << "'";
if (i < valid_options.size() - 1) oss << ", ";
}
oss << "\n";
}
if (!example.empty()) {
oss << " Example: " << example;
}
return oss.str();
}
inline std::string
get_json_value_string(
const nlohmann::json &j,
const std::string &field_name) {
if (!j.contains(field_name)) {
return "missing";
}
const auto &value = j[field_name];
std::ostringstream oss;
oss << value.dump();
if (value.is_null()) {
oss << " (type: null)";
} else if (value.is_boolean()) {
oss << " (type: boolean)";
} else if (value.is_number_integer()) {
oss << " (type: integer)";
} else if (value.is_number_float()) {
oss << " (type: float)";
} else if (value.is_string()) {
oss << " (type: string)";
} else if (value.is_array()) {
oss << " (type: array)";
} else if (value.is_object()) {
oss << " (type: object)";
}
return oss.str();
}
std::vector<std::string>
list_valid_field_modifiers();
inline std::string
format_unknown_modifier_error(
const std::string &invalid_type,
const std::string &context = "field modifier") {
auto valid_types = list_valid_field_modifiers();
std::ostringstream oss;
oss << "Unknown " << context << " type: '" << invalid_type << "'\n";
oss << " Valid types:\n";
for (const auto &type : valid_types) {
oss << " - " << type << "\n";
}
oss << " Check spelling and see documentation for details.";
return oss.str();
}
}
}
#endif