#pragma once
#include <iostream>
#include "SendDevice.h"
#include "CSerialPort/SerialPort.h"

#include <iostream>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <vector>
#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;

using namespace itas109;

typedef struct{
    int deviceId;
    uint8_t msgId;
    uint8_t data;
}GasV1Control;


// 设备Token
enum DeviceToken { 
    serial = 0,
    http = 1,
    tcp = 2
};

class deviceBase
{
protected:
    std::string deviceId;
    enum DeviceToken deviceToken = serial;
    std::string DeviceInfo = "";
    // deviceToken为serial时有效
    int baudRate = itas109::BaudRate115200;

    std::string ServerIp;
    std::string ServerCname;
    std::string ServerCpwd;

    int Type =  0;
public:
    deviceBase(){}
    ~deviceBase(){}
    
    virtual void serialization(){}
    virtual bool deserialization(){}
    virtual bool Consumer(uint8_t *data, int len, int &msg_id){return true;}
    virtual bool getStatusMsg(int &msg_id){ return false;};
    virtual void BuildDeviceInfo(SendDevice& sendDevice) {};

    virtual void setControlType(int type){
        this->Type = type;
    };

    virtual int32_t Open(std::string DeviceId,uint8_t* data, int& length){return 0;};
    virtual int32_t Close(std::string DeviceId, uint8_t* data, int&length){return 0;};
    virtual int32_t Fire(std::string DeviceId, uint8_t* data, int& length){return 0;};
    virtual int32_t Status(std::string DeviceId, uint8_t* data, int& length){return 0;};

    void setDeviceId(std::string DeviceId){
        deviceId = DeviceId;
    }
    std::string getDeviceId(){
        return deviceId;
    }

    void setDeviceToken(enum DeviceToken mdeviceToken){
        deviceToken = mdeviceToken;
    }
    
    enum DeviceToken getDevcieToken(){
        return deviceToken;
    }

    void setDeviceInfo(std::string deviceInfo){
        this->DeviceInfo = deviceInfo;
    }

    std::string getDeviceInfo(){
        return this->DeviceInfo;
    }

    void setBaudRate(int BaudRate){
        this->baudRate = BaudRate;
    }

    int getBaudRate(){
        return this->baudRate;
    }

    void setServerIp(std::string serverIp){
        ServerIp = serverIp;
    }

    void setServerCname(std::string serverCname){
        ServerCname = serverCname;
    }

    void setServerCpwd(std::string serverCpwd){
        ServerCpwd = serverCpwd;
    }
};
