#pragma once

#include <Core/Common/String.h>
#include <Core/Container/Vector.h>

namespace Romeo
{
    enum class JsonType
    {
        Null,
        Bool,
        Number,
        String,
        Array,
        Object
    };

    struct JsonValue;

    struct JsonKeyValue
    {
        Juliet::String Key;
        // Pointer is used here since JsonValue contains JsonKeyValue, forming mutual dependency
        JsonValue* Value = nullptr;
    };

    struct JsonValue
    {
        JsonType Type = JsonType::Null;
        bool BoolVal = false;
        double NumVal = 0.0;
        Juliet::String StrVal = {};

        Juliet::VectorArena<JsonValue, 32> ArrayVal = {};
        Juliet::VectorArena<JsonKeyValue, 32> ObjectVal = {};
    };

    // Parses a JSON string. Memory is allocated on the provided arena.
    [[nodiscard]] bool Json_Parse(Juliet::Arena* arena, const Juliet::String& jsonStr, JsonValue& outValue);

    // Queries a nested string value by path (e.g., "candidates/0/content/parts/0/text" or "response").
    [[nodiscard]] bool Json_Query(const JsonValue& root, const char* path, Juliet::String& outResult);

    // Escapes a string to be safely embedded inside JSON.
    [[nodiscard]] Juliet::String Json_EscapeString(Juliet::Arena* arena, const Juliet::String& str);
}
