/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-06 10:09:11
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-04-26 11:59:09
 */
#include "K8sServerResultMsy.hpp"

/**
 * @description: objectToJson
 * @param {string&} str
 * @return {*}
 */
template <typename T>
void K8sServerResultMsy<T>::objectToJson(std::string& str){
    return;
}

/**
 * @description: jsonToObject
 * @param {string&} json
 * @return {*}
 */
template <typename T>
bool K8sServerResultMsy<T>::jsonToObject(const std::string& json){
    rapidjson::Document doc;
    if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
        return false;
    }

    // get members
    const auto end = doc.MemberEnd();
    if (end == doc.FindMember("kind") || !doc["kind"].IsString()) {
        return false;
    } else {
        kind = doc["kind"].GetString();
    }
    
    if (end == doc.FindMember("apiVersion") || !doc["apiVersion"].IsString()) {
        return false;
    } else {
        apiVersion = doc["apiVersion"].GetString();
    }
    
    if (end != doc.FindMember("items")) {
       if(doc["items"].IsArray()){
            const rapidjson::Value& objs = doc["items"];
            for (size_t i = 0; i < objs.Size(); ++i) {
                const rapidjson::Value& obj = objs[i];
                T item;
                if(!(item.jsonToObject(obj))){
                    return false;
                }
                items.push_back(item);
            }
        }
    }
    
    return true;
}

/**
 * @description: jsonToObject
 * @param {Value&} object
 * @return {*}
 */
template <typename T>
bool K8sServerResultMsy<T>::jsonToObject(const rapidjson::Value& object){
    
    return true;
}