/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-06 10:03:42
 * @LastEditors: Your Name lishengyin@sz-sunwin.com
 * @LastEditTime: 2022-06-16 21:53:23
 */
#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"

#include <unistd.h>
#include <atomic>
#include <bitset>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <thread>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace toolkit;
using namespace std;

class MsgBase
{
public:
    int USERID;
    int ID;
    std::string DATATIME;
public:
    using Ptr = std::shared_ptr<MsgBase>;

    MsgBase(){}
    ~MsgBase(){}


    /**
     * @description: Object To Json
     * @param {Value&} object
     * @return {*}
     */    
    virtual std::string objectToJson(const rapidjson::Value& object){
        rapidjson::StringBuffer buffer;
	    rapidjson::Writer<rapidjson::StringBuffer> write(buffer);
        object.Accept(write);
        return buffer.GetString();
    }

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

    /**
     * @description: objectToJson
     * @return {*}
     */    
    virtual void ObjectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){}
    
    /**
     * @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;}

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

    /**
     * @description: 获取时间
     * @param {*}
     * @return {*}
     */    
    static std::string getDataTime(){
        char ctime[80];
        time_t rawtime;
        struct tm *info;
        time(&rawtime);
        info = localtime(&rawtime);
        strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
        std::string DataTime = ctime;
        return DataTime;
    }
};


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