/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-25 11:40:55
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-04-28 15:23:07
 */
#include "KubusphrereToken.hpp"


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


}

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

/**
 * @description: jsonToObject
 * @param {string&} json
 * @return {*}
 */    
bool KubusphrereToken::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("access_token") || !doc["access_token"].IsString()) {
        return false;
    } else {
        access_token = doc["access_token"].GetString();
    }

    if (end == doc.FindMember("token_type") || !doc["token_type"].IsString()) {
        return false;
    } else {
        token_type = doc["token_type"].GetString();
    }

    if (end == doc.FindMember("refresh_token") || !doc["refresh_token"].IsString()) {
        return false;
    } else {
        refresh_token = doc["refresh_token"].GetString();
    }
    if (end == doc.FindMember("expires_in") || !doc["expires_in"].IsInt()) {
        return false;
    } else {
        expires_in = doc["expires_in"].GetInt();
    }
    return true;
}