/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-02-15 15:48:43
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-02-16 09:24:27
 */
#ifndef __PALYERDEVCELIST_H_
#define __PALYERDEVCELIST_H_

#include <iostream>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>

using namespace std;


class dSocket
{
public:
    bool removed;
public:
    dSocket() {}
    ~dSocket() {}

    bool jsonToObject(const rapidjson::Value& object){
        const auto end = object.MemberEnd();
        if(end == object.FindMember("removed") || !object["removed"].IsBool()){
            return false;
        }else{
            removed = object["removed"].GetBool();
        }
        return true;
    }
};


class PlayerDeviceList
{
public:
    dSocket d_socket;
    std::string d_status;
    std::string did;
    std::string dname;
    std::string donline;
    std::string dtype;
    std::string ip_port;
    std::string loginDate;

public:
    PlayerDeviceList(){}
    ~PlayerDeviceList(){}

    /**
     * @description: json转换为对象
     * @param {Value&} object
     * @return {*}
     */    
    bool jsonToObject(const rapidjson::Value& object){
        const auto end = object.MemberEnd();

        if(end == object.FindMember("d_socket") || !object["d_socket"].IsObject()){
            return false;
        }
        else{
            const rapidjson::Value& obj = object["d_socket"];
            if(d_socket.jsonToObject(obj) == false) return false;
        }

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

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

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

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

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

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

        return true;
    }
};




#endif
