/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-06 10:03:42
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-04-24 15:23:10
 */
#ifndef __K8sServerBase_HPP_
#define __K8sServerBase_HPP_

#include <iostream>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <vector>
#include "Util/SqlPool.h"

using namespace toolkit;
using namespace std;

class MsgBase
{
public:
    using Ptr = std::shared_ptr<MsgBase>;

    MsgBase(){}
    ~MsgBase(){}

    /**
     * @description: objectToJson
     * @param {string&} str
     * @return {*}
     */    
    virtual void objectToJson(std::string& str) {}
    
    /**
     * @description: jsonToObject
     * @param {string&} json
     * @return {*}
     */    
    virtual bool jsonToObject(const std::string& json) {return true;}

    /**
     * @description: jsonToObject
     * @param {Value&} object
     * @return {*}
     */    
    virtual bool jsonToObject(const rapidjson::Value& object) {return true;}

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


class Metadata:virtual MsgBase
{
public:
    std::string resourceVersion;
public:
    Metadata(){}
    ~Metadata(){}

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

    /**
     * @description: jsonToObject
     * @param {string&} json
     * @return {*}
     */    
    bool jsonToObject(const std::string& json) {
        return true;
    } 

    /**
     * @description: jsonToObject
     * @param {Value&} object
     * @return {*}
     */    
    bool jsonToObject(const rapidjson::Value& object) override{
        const auto end = object.MemberEnd();
        if(end == object.FindMember("resourceVersion") || !object["resourceVersion"].IsString()){
            return false;
        }else{
            resourceVersion = object["resourceVersion"].GetString();
        }
        return true;
    }
};












#endif