/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-26 11:50:14
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-04-26 14:41:01
 */
#ifndef _KUBESPHERERESOURCESMSG_HPP_
#define _KUBESPHERERESOURCESMSG_HPP_


#include "K8sServerBase.hpp"
#include <vector>

template<typename T>
class KubeSphereResourcesMsg:public MsgBase
{
public:
    vector<T> items;
public:
    KubeSphereResourcesMsg(){}
    ~KubeSphereResourcesMsg(){}

    /**
     * @description: objectToJson
     * @param {string&} str
     * @return {*}
     */    
    void objectToJson(std::string& str) override{

    }

    /**
     * @description: jsonToObject
     * @param {string&} json
     * @return {*}
     */    
    bool jsonToObject(const std::string& json) override{
        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("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 {*}
     */    
    bool jsonToObject(const rapidjson::Value& object) override{
        return true;
    }

    /**
     * @description: ObjectToSql
     * @param {string&} sql
     * @return {*}
     */    
    virtual bool ObjectToSql(std::string& sql) override{
        return true;
    }
};





#endif