#ifndef DATATYPEDEF_H
#define DATATYPEDEF_H

#include <QtEndian>
#include <QList>
#include <QString>
#include <QMap>
#include <QMetaType>

// 配置文件内的 object key
namespace Config {
    namespace Keys {
        constexpr const char* TCP_SERVER                            = "tcp_server";
        constexpr const char* LOGIN                                 = "login";
        constexpr const char* OPERATOR                              = "operator";
        constexpr const char* LANGUAGE                              = "language";
        constexpr const char* TIME_ZONE                             = "time_zone";
        constexpr const char* RS485_PORT_NAME                       = "rs485_port_name";
        constexpr const char* ERROR_TIPS_VISIBLE                    = "error_tips_visible";
        constexpr const char* CURRENT_PREPARE_FORM                  = "current_prepare_form";
        constexpr const char* CCU_CONFIG_PATH                       = "ccu_config_path";
        constexpr const char* PCU_CONFIG_PATH                       = "pcu_config_path";
        constexpr const char* PRICE_INFO_PARH                       = "price_info_path";
        constexpr const char* OCPP16_AUTHORIZATION_PATH             = "ocpp16_authorization_path";
        constexpr const char* OCPP16_CHARGING_PROFILE_PATH          = "ocpp16_charging_profile_path";
        constexpr const char* OCPP16_CONFIG_KEY_PATH                = "ocpp16_config_key_path";
        constexpr const char* OCPP16_OFFLINE_CHARGING_RECORDS_PATH  = "ocpp16_offline_charging_records_path";
        constexpr const char* ERROR_CODE_NOTE_PATH                  = "error_code_note_path";
        constexpr const char* GUN_LINE_TEMPERATURE_VISIBLE          = "gun_line_temperature_visible";
        constexpr const char* CHARGING_STRECT                       = "charge_layout_strect";
        constexpr const char* SOC_STRECT                            = "soc_layout_strect";
        constexpr const char* FINISH_STRECT                         = "finish_layout_strect";
        constexpr const char* LOCAL_AUTH_LIST                       = "LocalAuthorizationList";
        constexpr const char* AUTH_CACHE                            = "AuthorizationCache";
        constexpr const char* LOG_CONFIG                            = "log_config";
        constexpr const char* AUTH_TYPE_ENABLE                      = "auth_type_enable";
        constexpr const char* TIME_OUT                              = "time_out";
        constexpr const char* PAYMENT_CONFIG                        = "payment_config";

        namespace Payment {
        }
    }

    namespace Language {
        constexpr const int SYSTEM  = 0x0;
        constexpr const int ENGLISH = 0x1;
        constexpr const int CHINESE = 0x2;
    }
}

namespace General {
    namespace Form {
        constexpr const int LANGUAGE        = 0x0;
        constexpr const int ADMIN_PWD       = 0x1;
        constexpr const int CHARGING_SETUP  = 0x2;
    }
    namespace Type {
        constexpr const int VALUE       = 0x0;
        constexpr const int IP_ADDR     = 0x1;
        constexpr const int LONG_TEXT   = 0x2;
        constexpr const int DATE_TIME   = 0x3;
    }
}

// OCPP16 配置文件
namespace ChargingProfiles {
    namespace Purpose {
        constexpr const char* TX_PROFILE                = "TxProfile";              // 传输配置
        constexpr const char* TX_DEFAULT_PROFILE        = "TxDefaultProfile";       // 传输默认配置
        constexpr const char* CHARGE_POINT_MAX_PROFILE  = "ChargePointMaxProfile";  // 充电点最大充电配置
    }
    namespace Kind {
        constexpr const int     ABSOLUTE_ID     = 0x0;
        constexpr const char*   ABSOLUTE        = "Absolute";   // 绝对值
        constexpr const int     RELATIVE_ID     = 0x1;
        constexpr const char*   RELATIVE        = "Relative";   // 相对值
        constexpr const int     RECURRING_ID    = 0x2;
        constexpr const char*   RECURRING       = "Recurring";  // 循环
    }
    namespace RecurrencyKind {
        constexpr const int     NO_RECURRING_ID = 0x0;
        constexpr const char*   NO_RECURRING    = "NULL";       // 不循环
        constexpr const int     DAILY_ID        = 0x1;
        constexpr const char*   DAILY           = "Daily";      // 每日
        constexpr const int     WEEKLY_ID       = 0x2;
        constexpr const char*   WEEKLY          = "Weekly";     // 每周
        constexpr const int     WEEKDAYS_ID     = 0x3;
        constexpr const char*   WEEKDAYS        = "Weekdays";   // 工作日
        constexpr const int     WEEKENDS_ID     = 0x4;
        constexpr const char*   WEEKENDS        = "Weekends";   // 周末
    }
    namespace UnitType {
        constexpr const int     AMPERE_ID = 0x0;
        constexpr const char*   AMPERE    = "A";      // 安培
        constexpr const int     WATT_ID   = 0x1;
        constexpr const char*   WATT      = "W";      // 瓦特
    }
}

// 全局变量名
namespace Global {
    namespace Keys {
        constexpr const char* GUN_BASIC_INFO_1          = "m_gun_basic_info_1";
        constexpr const char* GUN_BASIC_INFO_2          = "m_gun_basic_info_2";
        constexpr const char* CHARGING_INFO_1           = "m_charging_info_1";
        constexpr const char* CHARGING_INFO_2           = "m_charging_info_2";
        constexpr const char* GUN_ERROR_1               = "m_gun_error_1";
        constexpr const char* GUN_ERROR_2               = "m_gun_error_2";
        constexpr const char* GUN_STATE_1               = "m_gun_state_1";
        constexpr const char* GUN_STATE_2               = "m_gun_state_2";
        constexpr const char* GUN_TYPE_1                = "m_gun_type_1";
        constexpr const char* GUN_TYPE_2                = "m_gun_type_2";
        constexpr const char* TCU_CFG                   = "m_tcu_cfg";
        constexpr const char* CCU_CFG                   = "m_ccu_cfg";
        constexpr const char* PCU_CFG                   = "m_pcu_cfg";
        constexpr const char* PRICEINFO                 = "m_price_info";
        constexpr const char* VERSION                   = "m_version_info";
        constexpr const char* AUTH_LIST                 = "m_auth_list";
        constexpr const char* CHARGING_PROFILES         = "m_charging_profiles";
        constexpr const char* CHARGING_PROFILES_MAP     = "m_charging_profiles_map";
        constexpr const char* CFG_KEY                   = "m_cfg_key";
        constexpr const char* OFFLINE_CHARGING_RECORDS  = "m_chargings_records";
    }
}

namespace Pos {
    namespace CardType {
        constexpr const char* VISA              = "01";
        constexpr const char* MASTER            = "02";
        constexpr const char* AMEX              = "03";
        constexpr const char* DISCOVER          = "04";
        constexpr const char* DINERS            = "05";
        constexpr const char* CHINA_UNION_PAY   = "18";
        constexpr const char* MAEXTRO           = "19";
        constexpr const char* UNKNOWN           = "99";
    }

    namespace EnableCardUniqueIdentifier {
        constexpr const char* ENABLE    = "Off";
        constexpr const char* DISABLE   = "On";
    }

    namespace ConstValue {
        namespace ResponseCode {
            constexpr const char* OK                    = "000000";
            constexpr const char* HOST_ERROR_MESSAGE    = "110000";
            constexpr const char* CODE_MESSAGE          = "110000";
        }
        namespace StateCode {
            constexpr const char* WAITING_FOR_CARD              = "90000000";
            constexpr const char* WAITING_FOR_PIN_ENTRY         = "90000001";
            constexpr const char* ONLINE_PROCESSING             = "90000003";
            constexpr const char* WAITING_FOR_PIN_RE_ENTRY      = "90000006";
            constexpr const char* PLEASE_SEE_PHONE              = "90000007";
            constexpr const char* WAITING_FOR_TRY_ANOTHER_CARD  = "90000008";
            constexpr const char* PLEASE_PRESENT_ONE_CARD_ONLY  = "90000009";
            constexpr const char* FALLBACK_WAITING_FOR_SWIPE    = "90000010";
            constexpr const char* WAITING_FOR_REMOVE_CARD       = "90000011";
            constexpr const char* WAITING_FOR_RE_INSERT_CARD    = "90000012";
        }
    }
}

// 配置文件、日志文件路径
#ifdef Q_OS_WIN
#define TCU_CONFIG_FILE_PATH            QString(QDir::currentPath() + "/cfg/tcu_config.json")
#define LOG_FILE_PATH                   QString(QDir::currentPath() + "/log/")
#endif

#ifdef Q_OS_LINUX
#define TCU_CONFIG_FILE_PATH            "/home/root/cfg/tcu_config.json"
#define LOG_FILE_PATH                   "/home/root/log"
// #define TCU_CONFIG_FILE_PATH            "/home/ljh/Work/TchargeManageSys/cfg/tcu_config.json"
// #define LOG_FILE_PATH                   "/home/ljh/Work/TchargeManageSys/log"
#endif

#define TO_STRING(x) #x
#define VALUE_TO_STRING(x) TO_STRING(x)

namespace Constants {
    constexpr const int START_TIME_VAL            = 2;
    constexpr const int USER_ACTION_TIMEOUT       = 60;
    constexpr const int GUN_CTL_CMD_REPLY_TIMEOUT = 60;
    constexpr const int AUTHENTICATION_TIMEOUT    = 90;
    constexpr const int NFC_RS485_TX_TIMEOUT      = 3;
}

namespace Control {
    constexpr const int START_AUTH = 0x1;
    constexpr const int STOP_AUTH = 0x0;
}

// TCU 与 CCU 通信命令码
#define CHARGE_GUN_BASIC_INFO_CMD   0x90                // 充电枪基本信息
#define CHARGE_GUN_CHARGE_INFO_CMD  0x91                // 充电枪充电信息
#define CHARGE_GUN_START_CMD        0x92                // 充电枪启动命令
#define CHARGE_GUN_STOP_CMD         0x93                // 充电枪停止命令
#define CHARGE_GUN_AUTH_CMD         0x94
#define CHARGE_GUN_QR_CMD           0x95
#define HEARTBEAT_REPLY_CMD         0x03

// 充电枪默认ID
#define CHARGE_GUN_DEFAULT_1        0x1
#define CHARGE_GUN_DEFAULT_2        0x2

#define START_CHARGING_AUTH         0x0
#define STOP_CHARGING_AUTH          0x1

// 充电枪错误最大索引
#define CHARGE_GUN_ERROR_MAX_INDEX  GUNERROR_LINE_OVERTEMP

// M4255 NFC
#define M4255_RS485ADDR             0x20

#define M4255_CARD_CMD              0x01
#define M4255_READER_GET            0x02
#define M4255_READER_SET            0x03
#define M4255_OTHER_CMD             0x04

#define M4255_CMD_READ_CARDID               0xA1
#define M4255_CMD_READ_DATABLOCK_USEKEYB    0x5C
#define M4255_CMD_READ_DATABLOCK_USEKEYA    0xA3
#define M4255_CMD_FILL_DATABLOCK_USEKEYB    0x5B
#define M4255_CMD_FILL_DATABLOCK_USEKEYA    0xA4
#define M4255_CMD_FILL_PIN                  0xC3
#define M4255_CMD_FILL_ORG                  0xC4
#define M4255_CMD_FILL_PINBLOCK_USEKEYB     0x5A
#define M4255_CMD_FILL_PINBLOCK_USEKEYA     0xA5
#define M4255_CMD_INIT_PREPAIDIC_USEKEYB    0x59
#define M4255_CMD_INIT_PREPAIDIC_USEKEYA    0xA6
#define M4255_CMD_SUB_PREPAIDIC_USEKEYB     0x58
#define M4255_CMD_SUB_PREPAIDIC_USEKEYA     0xA7
#define M4255_CMD_ADD_PREPAIDIC_USEKEYB     0x57
#define M4255_CMD_ADD_PREPAIDIC_USEKEYA     0xA8
#define M4255_CMD_READ_PREPAIDIC_USEKEYB    0x57
#define M4255_CMD_READ_PREPAIDIC_USEKEYA    0xA8
#define M4255_CMD_SET_BEEP                  0xC2
#define M4255_CMD_FORCE_BEEP_ON             0xD1
#define M4255_CMD_FORCE_BEEP_OFF            0xD2
#define M4255_CMD_SET_WORK_MODE             0xC1
#define M4255_CMD_SET_READ_ONCE             0xC8

#define M4255_CMD_MODE                      0x01
#define M4255_AUTO_READ_CARDID              0x02
#define M4255_AUTO_READ_DATABLOCK           0x03
#define M4255_AUTO_READ_CARDID_DATABLOCK    0x04

#define M4255_READ_ONLYONCE         0x00
#define M4255_READ_CONTINUE         0x01

/*  通讯模块  */
/**
 * @brief The globals_keys_enum enum                    全局变量键值映射表
 */
enum globals_keys_enum {
    GLOBALS_GUN_BASIC_INFO_KEY_1 = 0x1,
    GLOBALS_GUN_BASIC_INFO_KEY_2,
    GLOBALS_CHARGING_INFO_KEY_1,
    GLOBALS_CHARGING_INFO_KEY_2,
    GLOBALS_GUN_ERROR_KEY_1,
    GLOBALS_GUN_ERROR_KEY_2,
    GLOBALS_GUN_STATE_KEY_1,
    GLOBALS_GUN_STATE_KEY_2,
    GLOBALS_GUN_TYPE_KEY_1,
    GLOBALS_GUN_TYPE_KEY_2,
    GLOBALS_AUTH_LIST_KEY,
    GLOBALS_CCU_CFG_KEY,
    GLOBALS_CHARGING_PROFILES_KEY,
    GLOBALS_CFG_KEY_KEY,
    GLOBALS_OFFLINE_CHARGING_RECORDS_KEY,
    GLOBALS_TCU_CFG_KEY,
    GLOBALS_PCU_CFG_KEY,
    GLOBALS_PRICE_INFO_KEY,
    GLOBALS_VERSION_KEY
};

/**
 * @brief The init_error_enum enum                      初始化错误码
 */
enum init_error_enum {
    INIT_OK = 0x0,
    INIT_CONFIG_LOAD_ERROR,
    INIT_LOGGER_MANAGER_ERROR,
    INIT_TCP_SERVER_ERROR,
    INIT_GUI_STYLE_LOAD_ERROR,
    INIT_GLOBALS_VALUE_ERROR
};

/**
 * @brief The message_head_t class                      TCU 与 CCU 通讯帧头
 */
typedef struct message_head_t{
    uint16_t    trans_id;           // 标志某个Modbus询问/应答的传输，由modbus主端生成，应答端复制
    uint16_t    proto_id;           // 固定字段0x0000
    uint16_t    length;             // 后续字节计数
    uint8_t     unit_id;            // 终端ID一般表示485地址，此处表示TCU的序号
    uint8_t     cmd;                // 标准modbus RTU和TC扩展（见后续），此处专指TC扩展
}MSG_HEAD;
Q_DECLARE_METATYPE(MSG_HEAD)
#define MESSAGE_HEAD_LENGTH (8)

/**
 * @brief The log_level_enum enum                       日志级别定义
 */
enum log_level_enum {
    ALL = 0,
    DEBUG,
    INFO,
    WARNING,
    ERROR,
    FATAL
};

// 定义一个枚举类型，表示充电进度
enum charge_progress_enum {
    PLUG_IN_PROGRESS = 0x0,
    AUTHORIZATION_PROGRESS,
    CHARGING_PROGRESS,
    FINISHED_PROGRESS,
    UNKNOWN_PROGRESS = 0xFF
};

enum charge_finish_state_enum {
    NORMAL_FINISH = 0x0,
    RECOVERABLE_FINISH,
    IRRECOVERABLE_FINISH
};

namespace AuthError {
    constexpr int SUCCESS                       = 0;        // 成功
    constexpr int CHARGING                      = 1;        // 充电中
    constexpr int INIT_FAILED                   = 2;        // 初始化失败
    constexpr int TIMEOUT                       = 3;        // 超时
    constexpr int READ_CARD_FAILED              = 4;        // 读取卡片信息失败
    constexpr int INVALID_CARD_ID               = 5;        // 无效卡号
    constexpr int SERIAL_PORT_ERROR             = 6;        // 串口名称错误
    constexpr int WAITING_FOR_OTHER_INSTANCE    = 7;        // 等待其他实例
    constexpr int AUTH_FAILD                    = 8;        // 鉴权失败
}

namespace AuthType {
    constexpr int QR = 0;                               // 二维码
    constexpr int CARD = 1;                             // IC卡
    constexpr int POS = 2;                              // POS机
    constexpr int QR_OR_CARD = 3;                       // 二维码或 IC 卡 
    constexpr int QR_OR_POS = 4;                        // 二维码或 POS 机
    constexpr int CARD_OR_POS = 5;                      // IC 卡或 POS 机
    constexpr int NO_QR = 6;                            // 无二维码
    constexpr int NO_CARD = 7;                          // 无 IC 卡
    constexpr int NO_POS = 8;                           // 无 POS 机
    constexpr int NO_QR_OR_CARD = 9;                    // 无二维码或 IC 卡
    constexpr int NO_QR_OR_POS = 10;                    // 无二维码或 POS 机
    constexpr int NO_CARD_OR_POS = 11;                  // 无 IC 卡或 POS 机
}

namespace GunError {
constexpr int GUN_UNAVAILABEL = 0x1;                        // 不可用
constexpr int GUN_TCP_DISCONNECT = 0x11;                    // TCP 断开
constexpr int GUN_TCP_NO_CLIENT = 0x12;                     // 无客户端
constexpr int GUN_TCP_HEART_TIMIEOUT = 0x13;                // 心跳超时
constexpr int GUN_OUT_OF_SERVICE = 0x2;                     // 离线
constexpr int GUN_MAX_POWER_LIMIT = 0x3;                    // 最大功率限制
}

/**
 * @brief The workspace_form_enum enum                  主页工作区窗口索引
 */
// enum workspace_form_enum {
//     STANDBY = 0x0,
//     SETTLEMENT_FORM,
//     GUN_DETAIL,
//     SETTINGS,
//     GENERAL_SETTINGS,
//     DEVICE_INFORMATION,
//     CONFIGURATION_KEY,
//     CHARGING_RECORDS,
//     FIRMWARE_INFORMATION,
//     IMPORT_EXPORT,
//     LOG_VIEW,
//     LOG_SHOW,
//     PAYMENT,
//     LANGUAGE,
//     ADMIN_PWD,
//     CHARGING_SETUP
// };

namespace Workspace {
    namespace Home {
        constexpr const int STANDBY     = 0x0000;
        constexpr const int SETTINGS    = 0x1000;
    }
    namespace Settings {
        constexpr const int CCU                     = 0x1100;
        constexpr const int TCU                     = 0x1200;
        constexpr const int PCU                     = 0x1300;
        constexpr const int OCPP                    = 0x1400;
        constexpr const int OTHER                   = 0x1500;
        namespace Ccu {
            constexpr const int CHARGE_GUN              = 0x1110;
            namespace ChargeGun {
                constexpr const int CHARGE_GUN_1        = 0x1111;
                constexpr const int CHARGE_GUN_2        = 0x1112;
            }
            constexpr const int AUTH                    = 0x1120;
            constexpr const int OFFLINE_PRICES          = 0x1130;
            constexpr const int PCUHW                   = 0x1140;
            constexpr const int PCUTC                   = 0x1150;
            constexpr const int QTTCU                   = 0x1160;
            constexpr const int OCPP16                  = 0x1170;
            constexpr const int OCPP21                  = 0x1180;
        }
        namespace Tcu {
            constexpr const int GENERAL                     = 0x1210;
            constexpr const int DWELL_TIME                  = 0x1220;
        }
        namespace Pcu {
            constexpr const int GENERAL                     = 0x1310;
        }
        namespace Ocpp {
            constexpr const int CONFIG_KEY                  = 0x1410;
            constexpr const int LOCAL_AUTH_LIST             = 0x1420;
            constexpr const int AUTH_CACHE                  = 0x1430;
            constexpr const int CHARGING_PROFILES           = 0x1440;
            namespace ChargingProfiles {
                constexpr const int CHARGE_POINT_MAX_PROFILE    = 0x1441;
                constexpr const int TX_DEFAULT_PROFILE          = 0x1442;
                constexpr const int TX_PROFILE                  = 0x1443;
            }
        }
        namespace Other {
            constexpr const int DEVICE_INFO                 = 0x1510;
            constexpr const int FIRMWARE_INFO               = 0x1520;
            constexpr const int CHARGING_RECORDS            = 0x1530;
            constexpr const int ERROR_CODE_NOTE             = 0x1540;
        }
        namespace Charging{}
        namespace Device{}
        namespace Firmware{}
        namespace General{
            constexpr const int LANGUAGE                = 0x1110;
            constexpr const int ADMIN_PWD               = 0x1120;
            constexpr const int CHARGING_SETUP          = 0x1130;
            constexpr const int DWELL_TIME              = 0x1140;
            constexpr const int SCREEN_BRIGHTNESS       = 0x1150;
            constexpr const int NETWORK_SETUP           = 0x1160;
            constexpr const int WORK_MODE               = 0x1170;
            namespace ChargingSetup {
                constexpr const int AC_THRESHOLD                = 0x1131;
                constexpr const int ADVANCED_CHARGING           = 0x1132;
                constexpr const int AUTH_CONFIG                 = 0x1133;
                constexpr const int CHARGE_GUN_TYPE             = 0x1134;
                constexpr const int OCPP_SYSTEM                 = 0x1135;
                constexpr const int PILE_TIP_OVER_TEMPERATURE   = 0x1136;
                constexpr const int SMART_CHARGING              = 0x1137;
            }
        }
        namespace Configkey{}
        namespace Log{
            constexpr const int LOG_SHOW                        = 0x1710;
        }
        namespace Payment{}
        namespace Transfer{}
    }
}

enum charge_prepare_enum {                              //
    PLUG_IN = 0,
    AUTHENTICATION,
    CHARGE_PREPARE,
    CHARGING_FORM,
    FINISH_FORM,
    ERROR_FORM
};

enum gui_state_enum {
    CHARGE_GUN_AVAILABLE = 0x0,
    AUTHORIZATION_QR,
    AUTHORIZATION_ID_CARD,
    AUTHORIZATION_QR_ID_CARD,
    WAITING_NO_ID_CARD,
    WAITING_NO_ID_CARD_QR,
    WAITING_STANDBY,
    AUTHORIZING_ONLINE,
    RETRY,
    TIMEOUT,
    RETRY_OR_RETURN_GUN,
    SCAN_QR_OR_RETURN_GUN,
    FAILED,
    CARD_AUTHORIZATION_FAILED,
    CHANGE_CARD,
    BALANCE_NO_START,
    TOP_UP_RETRY,
    PREPARE_HANDSHAKING,
    HANDSHAKING,
    CONFIGUING,
    START_CHARGING,
    STARTUP_FAILED,
    UNPLUG_RETRY_OR_CHANGE,
    STOP_CHARGING,
    TIME_REMAINING,
    RETURN_GUN,
    RESTART_CHARGING,
    CHARGING_STOP_ABNORMAL,
    UNAVAILABLE,
    CHARGE_GUN_UNAVILABLE,
    OUT_OF_SERVICE,
    MAX_POWER_LIMIT,
    UNKOWN_STATE = 0xFF
};

#define MAX_GUN_ERROR_CODE_NUM 32       // 最大充电枪错误码数量
/**
 * @brief The GUN_Error enum            充电枪错误码详解
 */
enum GUN_Error
{
    GUNERROR_NO_ERROR = 0x80000000,     // 错误开始标记
    GUNERROR_BOX_OVERTEMP,              // 箱体过温
    GUNERROR_SMOKE_ALARM,               // 烟感器报警
    GUNERROR_LGPTA_ALARM,               // 防雷器A报警
    GUNERROR_LGPTB_ALARM,               // 防雷器B报警
    GUNERROR_FANA_ALARM,                // 风扇A报警
    GUNERROR_FANB_ALARM,                // 风扇B报警
    GUNERROR_FANC_ALARM,                // 风扇C报警
    GUNERROR_LIQC_ALARM,                // 水冷系统报警
    GUNERROR_EMG_ALARM,                 // 急停报警
    GUNERROR_WAT_ALARM,                 // 水浸报警
    GUNERROR_GAT_ALARM,                 // 门禁报警
    GUNERROR_HPUMP_ALARM,               // 热泵系统报警
    GUNERROR_FUSE_ALARM,                // 熔断器报警
    GUNERROR_STALL_ALARM,               // 电子锁堵转报警
    GUNERROR_CONTACTOR_FAULT,           // 接触器拒动
    GUNERROR_LINE_OVERTEMP,             // 枪线过温
    GUNERROR_HANDSHAKE_FAULT,           // 车桩握手失败
    GUNERROR_INSULATION_FAULT,          // 绝缘检测失败
    GUNERROR_PRECHARGE_FAULT,           // 预充失败
    GUNERROR_CHARGING_FAULT,            // 充电失败
    GUNERROR_BMS_VOLTAGE_INVERSE,       // BMS 电池电压反接
    GUNERROR_BMS_CONTACTOR_FAULT,       // BMS 接触器拒动
    GUNERROR_BMS_VOLTAGE_MISSTACH,      // BMS 电压失调或者文波过大
    GUNERROR_BMS_CURRENT_MISSTACH,      // BMS 电流失调或者文波过大
    GUNERROR_CAN_OFFLINE,               // 国标枪CAN通信失败
    GUNERROR_PLC_OFFLINE,               // 美标和欧标PLC通信失败
    GUNERROR_STATE_ERROR,               // 美标和欧标CP状态错误，或者国标CC1状态错误
    GUNERROR_LAULT                      // 最后错误标记，将来继续扩展
};

#define MAX_GUN_STATE_CODE_NUM 32       // 最大充电枪状态数量
/**
 * @brief The GUN_State enum            充电枪状态信息
 */
enum GUN_State
{
    GUNSTATE_IDLE = 0,                  // 正常--枪归位枪座
    GUN_PLUGOUT,                        // 拔枪--准备连车
    GUN_PLUGIN,                         // 插枪--连车成功
    GUN_STARTUP,                        // 启动--枪座通电
    GUN_ELOCKED,                        // 锁枪--枪座锁枪
    GUN_AUTHORIZED,                     // 鉴权--枪座鉴权成功
    GUN_PARAMETERS,                     // 参数--枪座参数设置成功
    GUN_INSULATION,                     // 绝缘--枪座绝缘检测成功
    GUN_PRECHARGE,                      // 预充--枪座预充成功
    GUN_CHARGING,                       // 充电--枪座充电成功
    GUN_SUSPEND,                        // 暂停--枪座暂停成功
    GUN_STOPING,                        // 停止--枪座停止成功
    GUN_UNKNOW,                         // 未知--枪座未知状态
};

enum CHARGING_STATE {
    CCU_START_TR = 0x0,
    CCU_STOP_TR,
    AUTH_START,
    AUTH_SUCCESS,
    AUTH_FAILD,
    START_DEAL,
    STOP_DEAL,
};

#define MAX_GUN_TYPE_CODE_NUM 32        // 最大充电枪类型数量
enum GUN_Type
{
    GUNTYPE_NACS = 0,                   // 特斯拉充电接口，枪头和枪座，仅直流
    GUNTYPE_CCS1,                       // 美标枪充电接口，枪头和枪座混合单相交流和直流
    GUNTYPE_CCS2,                       // 欧标枪充电接口，枪头和枪座混合三相交流和直流
    GUNTYPE_CHADEMO,                    // 日标枪充电接口，枪头和枪座，仅直流
    GUNTYPE_GBDC,                       // 国标枪充电接口，枪头和枪座，仅直流
};

/**
 * @brief The charge_gun_basic_info_t class             充电枪基本信息
 */
typedef struct charge_gun_basic_info_t {
    uint32_t    GUNID;                  // 充电枪 ID
    uint32_t    GUN_Error;              // 错误码
    uint32_t    GUN_State;              // 充电枪状态信息
    uint32_t    GUN_Type;               // 充电枪类型
    uint32_t    BOX_temp;               //
}BASIC_INFO;
Q_DECLARE_METATYPE(BASIC_INFO)
typedef QMap<uint32_t, BASIC_INFO> BASIC_INFO_MAP;

/**
 * @brief The charge_gun_charge_info_t class            充电枪充电信息
 */
typedef struct charge_gun_charge_info_t {
    uint32_t    GUNID;                  // 充电枪 ID
    uint32_t    transactionId;          // 充电交易ID（CCU产生或者云平台产生的随机数）
    uint32_t    SOC;                    // 当前电量百分比
    uint32_t    startUTC;               // 充电开始时间
    uint32_t    now_UTC;                // 当前时间
    uint32_t    startKW;                // 充电开始电量
    uint32_t    now_KW;                 // 当前电量
    uint32_t    GUNLine_temp0;          // 充电枪线温度 1
    uint32_t    GUNLine_temp1;          // 充电枪线温度 2
    uint32_t    powerKW;                // 功率
    uint32_t    voltage;                // 电压
    uint32_t    current;                // 电流
}CHARGING_INFO;
Q_DECLARE_METATYPE(CHARGING_INFO)
typedef QMap<uint32_t, CHARGING_INFO> CHARGING_INFO_MAP;

/**
 * @brief The charge_gun_start_cmd_info_t class         充电枪启动命令
 */
typedef struct charge_gun_start_cmd_info_t {
    uint32_t    GUNID;                  // 充电枪 ID
    uint8_t     EMID[32];               // NFC卡ID
    uint32_t    requestKWs;             // 0代表不使用，大于0表示请求充电度数
    uint32_t    requestMinutes;         // 0代表不使用，大于0表示请求充电分钟数
    uint32_t    requestSOC;             // 0代表不使用，大于0表示充电到SOC值时，停止充电
    uint32_t    authorizationResult;    // 0表示需要CCU进行鉴权，1表示TCU已鉴权过（POS用）
}START_CHARGE_CMD;
Q_DECLARE_METATYPE(START_CHARGE_CMD)

typedef struct charge_gun_stop_cmd_info_t {
    uint32_t GUNID;                     // 充电枪 ID
    uint32_t EMID[32];                  // NFC卡ID
    uint32_t authorizated;              // 0表示需要CCU鉴权，1表示TCU已经鉴权
}STOP_CHARGE_CMD;
Q_DECLARE_METATYPE(STOP_CHARGE_CMD)

typedef struct charge_gun_auth_info_t {
    uint32_t    GUNID;
    uint8_t     EMID[32];
    uint32_t    requestKWs;
}GUN_AUTH;
Q_DECLARE_METATYPE(GUN_AUTH)

/**
 * @brief The ccu_reply_info_t class                    CCU 回复结构体
 */
typedef struct ccu_reply_info_t {
    uint32_t result;
}REPLY_INFO;
Q_DECLARE_METATYPE(REPLY_INFO)

/*  配置管理模块  */
/**
 * @brief The setting_index_enum enum               配置管理索引
 */
enum setting_index_enum {
    TCU_CONFIG = 0x0,                   // tcu 配置
    CCU_CONFIG,                         // ccu 配置
    PCU_CONFIG,                         // pcu 配置
    PRICEINFO,                          // 电价配置
    GUN_CONFIG,                         // 充电枪配置
    AUTHORIZATION,                      // 鉴权列表
    CHARGING_PROFILE,                   // 充电配置文件
    CONFIG_KEY,                         // oocp 配置
    CHARGING,                           // 充电记录
    ERROR_CODE_NOTE
};

/**
 * @brief The authorization_card_info_t class       授权 ID 卡片基本信息
 */
typedef struct authorization_card_info_t {
    QString     idTag;                  // id
    QString     expiryDate;             // 过期时间
    QString     parentIdTag;            // 父/子卡信息
    QString     status;                 // 卡片禁用状态信息
}AUTH_CARD_INFO;
Q_DECLARE_METATYPE(AUTH_CARD_INFO)

typedef struct authorization_list {
    QList<authorization_card_info_t> localAuthorizationList;
    QList<authorization_card_info_t> authorizationCache;
}AUTH_LIST;
Q_DECLARE_METATYPE(AUTH_LIST)

/**
 * @brief The tcp_server_cfg_info_t class           tcp 服务端配置
 */
typedef struct tcp_server_cfg_info_t {
    QString     address;                // 绑定 IP 地址
    int         port;                   // 绑定端口
}TCP_CFG;
Q_DECLARE_METATYPE(TCP_CFG)

/**
 * @brief The admin_cfg_info_t class                管理员账号密码
 */
typedef struct admin_cfg_info_t {
    QString     username;               // 用户名
    QString     password;               // 密码
}ADMIN_CFG;
Q_DECLARE_METATYPE(ADMIN_CFG)

typedef struct layout_strect_info_t {
    QList<int>              row_strect;                 // 行宽
    QList<int>              column_strect;              // 列宽
    QList<int>              once_row_strect;            // 单枪充电行宽
    QList<int>              once_column_strect;         // 单枪充电列宽
}STRECT_INFO;
Q_DECLARE_METATYPE(STRECT_INFO)

typedef struct error_code_note_info_t {
    uint32_t    error_code;                             // 错误码
    QString     error_note;                             // 错误信息
}ERROR_NOTE;
Q_DECLARE_METATYPE(ERROR_NOTE)
typedef QList<ERROR_NOTE> ERROR_NOTE_LIST;

typedef struct log_config_info_t {
    QString general_log_path = LOG_FILE_PATH;           // 日志文件路径
    QString ocpp16_log_path;                            // ocpp16 日志文件路径
    QString slave_log_path;                             // 下位机日志文件路径
    int     general_log_level;                          // 日志级别
    int     slave_log_level;                            // 下位机日志级别
    bool    ignored_duplicate_log;                      // 忽略重复日志
    int     single_log_size;                            // 日志文件大小
    int     total_log_size;                             // 日志文件总大小
    int     history_log_save_time;                      // 日志文件保存时间
}LOG_INFO;
Q_DECLARE_METATYPE(LOG_INFO)

typedef struct auth_type_enable_info_t {
    bool    nfc;
    bool    qr;
    bool    pos;
}AUTH_TYPE_ENABLE;
Q_DECLARE_METATYPE(AUTH_TYPE_ENABLE)

typedef struct time_out_info_t {
    int     tcp_client_recv{20};
    int     tcp_client_send{20};
    int     tcp_heartbeat{20};
    int     auth_form_wait_time{90};
}TIME_OUT;
Q_DECLARE_METATYPE(TIME_OUT)

typedef struct price_setting_info_t {
    bool    offline_pricing;                    // 离线计费
    int     offline_price_type;                 // 离线计费类型
    int     offline_price_timezone;             // 离线计费时区
    int     mini_amount_charging_permission;    // 最小充电金额权限
    int     currency_symbol;                    // 货币符号
    int     currency_code;                      // 货币代码 
    int     decimal_places_currency;            // 货币小数位
}PRICE_SETTING;
Q_DECLARE_METATYPE(PRICE_SETTING)

typedef struct pos_machine_info_t {
    QString pos_machine_manufacturer;
    bool    backout_pos_payment;
    bool    ocpp_online_pos_payment;
    QString id_token_prefix;
    int     max_payment_record_num;
    int     pos_max_wait_duration;
}POS_MACHINE;
Q_DECLARE_METATYPE(POS_MACHINE)

typedef struct pax_config_info_t {
    int     id_token_type;
}PAX_INFO;
Q_DECLARE_METATYPE(PAX_INFO)

typedef struct wizar_config_info_t {
    int     id_token_type;
}WIZAR_INFO;
Q_DECLARE_METATYPE(WIZAR_INFO)

typedef struct payment_config_info_t {
    PRICE_SETTING   price_setting;                  // 价格配置
    int             total_elec_energy_loss_ratio;   // 总电量损耗比例
    POS_MACHINE     pos_machine;                    // pos 配置     
    PAX_INFO        pax_config;                     // pax 配置
    WIZAR_INFO      wizar_config;                   // wizar 配置
}PAYMENT_INFO;
Q_DECLARE_METATYPE(PAYMENT_INFO)

/**
 * @brief The tcu_config_info_t class               TCU 终端软件配置
 */
typedef struct tcu_config_info_t {
    tcp_server_cfg_info_t   tcp_server_cfg;                         // tcp 服务端配置
    admin_cfg_info_t        operator_cfg;                           // 操作员用户信息配置
    admin_cfg_info_t        admin_cfg;                              // 管理员用户信息配置
    int                     language;                               // 界面语言
    int                     time_zone;                              // 界面时区
    LOG_INFO                log_config;                             // 日志配置
    QString                 ccu_config_path;                        // ccu 配置路径
    QString                 pcu_config_path;                        // pcu 配置路径
    QString                 price_info_path;                        // 价格信息路径
    QString                 ocpp16_authorization_path;              // ocpp16 鉴权配置路径
    QString                 ocpp16_charging_profile_path;           // ocpp16 充电配置路径
    QString                 ocpp16_config_key_path;                 // ocpp16 配置键值路径
    QString                 ocpp16_offline_charging_records_path;   // ocpp16 离线充电记录路径
    QString                 error_code_note_path;                   // 错误码提示路径
    QString                 rs485_port_name;                        // rs485 端口名称
    bool                    error_tips_visible;                     // 错误提示是否可见
    int                     current_prepare_form;                   // 当前准备表单
    bool                    gun_line_temperature_visible;           // 枪线温度是否可见
    STRECT_INFO             charge_layout_strect;                   // 充电布局
    STRECT_INFO             soc_layout_strect;                      // soc 布局
    STRECT_INFO             finish_layout_strect;                   // 结束布局
    ERROR_NOTE_LIST         error_code_note;                        // 错误码提示
    AUTH_TYPE_ENABLE        auth_type_enable;                       // 鉴权类型
    TIME_OUT                time_out;                               // 超时时间
    PAYMENT_INFO            payment_config;                         // 价格配置
}TCU_CFG;
Q_DECLARE_METATYPE(TCU_CFG)

typedef struct pcuhw_info_t {
    bool        enable;                 // 
    QString     connect_ip_string;      // 
    int         connect_port;           // 
    bool        enable_ssl;             // 
}PCUHW_CFG;
Q_DECLARE_METATYPE(PCUHW_CFG)

typedef struct pcutc_info_t {
    bool        enable;                 // 
    QString     connect_ip_string;      // 
    int         connect_port;           // 
    bool        enable_ssl;             // 
}PCUTC_CFG;
Q_DECLARE_METATYPE(PCUTC_CFG)

typedef struct ocpp1_6_info_t {
    bool        enable;                     // 
    QString     connect_ip_string;          // 
    int         connect_port;               // 
    QString     ssl_ca_filepath;            // 
    QString     ssl_cert_filepath;          // 
    QString     ssl_private_key_filepath;   // 
    bool        enable_ssl;                 // 
}OCPP1_6;
Q_DECLARE_METATYPE(OCPP1_6)

typedef struct ocpp2_1_info_t {
    bool        enable;
    QString     connect_ip_string;
    int         connect_port;
    QString     ssl_ca_filepath;
    QString     ssl_cert_filepath;
    QString     ssl_private_key_filepath;
    bool        enable_ssl;
}OCPP2_1;
Q_DECLARE_METATYPE(OCPP2_1)

typedef struct gun_detail_info_t {
    int         GUN_ID;                     // 枪ID
    QString     GUN_Type;                   // 枪类型
    bool        GUN_Available;              // 枪可用
    int         GUN_maxI;                   // 枪最大电流
    QString     slac_ifname;                // 通讯接口名称
    QString     can_ifname;                 // CAN 接口名称
    bool        QRCode_enable;              // 二维码是否可用
    QString     QRCode_URL;                 // 二维码 URL
    bool        requestPowerByMinutes;      // 根据分钟请求功率
    bool        requestPowerByPowerKW;      // 根据功率请求功率
    bool        requestPowerBySOC;          // 根据 SOC 请求功率
    int         GUNOverTemp_Warning;        // 枪线过温警告
    int         GUNOverTemp_Stopping;       // 枪线过温停止
    bool        enable_current_limit;       // 电流限制使能
    int         permitted_current;          // 
    bool        enable_powerKW_limit;       // 功率限制使能
    int         permitted_powerKW;          // 
}GUN_DETAIL;
Q_DECLARE_METATYPE(GUN_DETAIL)

typedef struct qttcu_info_t {
    bool        enable;
    QString     connect_ip_string;
    int         connect_port;
    bool        enable_ssl;
}QTTCU_CFG;
Q_DECLARE_METATYPE(QTTCU_CFG)

typedef struct ccu_config_info_t {
    int                     TCU_ID;                     // TCU ID
    int                     GUN_Numb;                   // 充电枪数量
    QString                 CCU_SN;                     // CCU SN
    QString                 CCU_Series;                 // CCU 系列
    QString                 CCU_Vendor;                 // CCU 厂商
    bool                    CCU_Available;              // CCU 型号
    QString                 username;                   // 用户名
    QString                 password;                   // 密码
    int                     BoxOverTemp_Warning;        // 枪线过温警告
    int                     BoxOverTemp_Stopping;       // 枪线过温停止
    bool                    enalbe_offline_price;       // 离线价格使能
    QString                 ISO4217_CurrencySymbol;     // 货币符号
    int                     ISO4217_MinorUnit;          // 货币最小单位
    int                     ISO4217_LeastSign;          // 货币小数位
    QList<GUN_DETAIL>       GUN_Detail;                 // 充电枪详细信息
    PCUHW_CFG               pcuhw;                      // PCU 硬件信息
    PCUTC_CFG               pcutc;                      // 
    QTTCU_CFG               qttcu;                      // TCU 通用配置
    QList<OCPP1_6>          ocpp16_list;                // OCPP1.6 通用配置
    QList<OCPP2_1>          ocpp21_list;                // OCPP2.1 通用配置
}CCU_CFG;
Q_DECLARE_METATYPE(CCU_CFG)

/**
 * @struct pcu_config_info_t PCU                        配置信息
 */
typedef struct pcu_config_info_t {
    QString     PCU_arch_type;              // PCU 架构类型
    QString     listen_if_name;             // 监听接口名称
    QString     listen_ip_string;           // 监听 IP 地址
    int         listen_port;                // 监听端口    
    
    QString     acdc_can_ifame;             // ACDC 接口名称
    int         adc_can_bitrate;            // ACDC 波特率
    QString     pdu_can_ifame;              // PDU 接口名称
    int         pdu_can_bitrate;            // PDU 波特率

    int         GUN_NUMB;                   // 枪数量
    int         PDU_NUMB;                   // PDU 数量
    int         ACDC_NUMB;                  // ACDC 数量
    int         ACDC_unit_kW;               // ACDC 单位

    QString     ACDC_module_vendor_name;    // ACDC 模块厂商名称
}PCU_CFG;
Q_DECLARE_METATYPE(PCU_CFG)

typedef struct offline_price_info_t {
    QString     startTime;                  // 开始时间
    QString     endTime;                    // 结束时间
    double      electrPrice;                // 电价
    double      servicePrice;               // 服务费
    double      durationPrice;              // 时长费
}OFFLINE_PRICE;
Q_DECLARE_METATYPE(OFFLINE_PRICE)

typedef struct price_info_t {
    QString                 type;               // 类型
    QString                 timezone;           // 时区
    double                  minAllowBalance;    // 最小允许余额
    QList<OFFLINE_PRICE>    price;              // 价格详细信息
}PRICE_INFO;
Q_DECLARE_METATYPE(PRICE_INFO)

typedef struct version_info_t {
    QString ccu_version;        // CCU 版本
    QString tcu_version;        // TCU 版本
    QString pcu_version;        // PCU 版本
    QString hw_version;         // 硬件版本
}VERSION;
Q_DECLARE_METATYPE(VERSION)

struct charging_schedule_period_info_t {
    int startPeriod = 0;        // 开始时间
    int limit{0};               // 限制
    int numberPhases = 3;       // 相位数
};
Q_DECLARE_METATYPE(charging_schedule_period_info_t)

struct charging_schedule_info_t {
    int                                     duration{0};
    QString                                 startTime{"NULL"};
    QString                                 chargingRateUnit{"W"};
    int                                     minChargingRate{200};
    QList<charging_schedule_period_info_t>  chargingSchedulePeriod{charging_schedule_period_info_t()};
};
Q_DECLARE_METATYPE(charging_schedule_info_t)

struct charging_profiles_detail_info_t {
    int                                 chargingProfileId{0};
    int                                 connectorId{0};
    int                                 stackLevel{0};
    
    QString                             validFrom{"NULL"};
    QString                             validTo{"NULL"};

    QString                             chargingProfilePurpose{"NULL"};
    QString                             chargingProfileKind{"Absolute"};
    QString                             recurrencyKind{"NULL"};
    
    charging_schedule_info_t            chargingSchedule{charging_schedule_info_t()};
};
Q_DECLARE_METATYPE(charging_profiles_detail_info_t)

typedef struct charging_profiles_info_t {
    int                                     count;
    int                                     maxLength;
    QList<charging_profiles_detail_info_t>  chargingProfiles;
}CHARGING_PROFILES;
Q_DECLARE_METATYPE(CHARGING_PROFILES)

typedef struct core_profile_info_t {
    bool            AllowOfflineTxForUnknownId;             // 允许未知 ID 离线交易
    bool            AuthorizationCacheEnabled;              // 启用授权缓存
    bool            AuthorizeRemoteTxRequests;              // 授权远程交易请求
    int             BlinkRepeat;                            // 闪烁重复
    int             ClockAlignedDataInterval;               // 时钟对齐数据间隔
    int             ConnectionTimeOut;                      // 连接超时
    QStringList     ConnectorPhaseRotation;                 // 连接器相位旋转
    int             ConnectorPhaseRotationMaxLength;        // 连接器相位旋转最大长度
    int             GetConfigurationMaxKeys;                // 获取配置最大键
    int             HeartbeatInterval;                      // 心跳间隔
    int             LightIntensity;                         // 亮度
    bool            LocalAuthorizeOffline;                  // 本地授权离线
    bool            LocalPreAuthorize;                      // 本地预授权
    int             MaxEnergyOnInvalidId;                   // 无效 ID 最大能量
    int             MeterValuesAlignedDataMaxLength;        // 对齐数据最大长度
    int             MeterValuesSampledDataMaxLength;        // 采样数据最大长度
    int             MeterValueSampleInterval;               // 电表值采样间隔
    int             MinimumStatusDuration;                  // 最小状态持续时间
    int             NumberOfConnectors;                     // 连接器数量
    int             ResetRetries;                           // 重试次数
    bool            StopTransactionOnEVSideDisconnect;      // EV 断开连接时停止交易
    bool            StopTransactionOnInvalidId;             // 无效 ID 时停止交易
    int             StopTxnAlignedDataMaxLength;            // 对齐数据最大长度
    int             StopTxnSampledDataMaxLength;            // 采样数据最大长度
    QStringList     SupportedFeatureProfiles;               // 支持的功能配置文件
    int             SupportedFeatureProfilesMaxLength;      // 支持的功能配置文件最大长度
    int             TransactionMessageAttempts;             // 交易消息尝试次数
    int             TransactionMessageRetryInterval;        // 交易消息重试间隔
    bool            UnlockConnectorOnEVSideDisconnect;      // EV 断开连接时解锁连接器
    int             WebSocketPingInterval;                  // WebSocket ping 间隔
    QString         AuthorizationKey;                       // 授权密钥
    int             AuthorizationCacheMaxLength;            // 授权缓存最大长度
}CORE_PROFILE;
Q_DECLARE_METATYPE(CORE_PROFILE)

typedef struct local_auth_list_manage_profile {
    bool            LocalAuthListEnabled;                   // 启用本地授权列表
    int             LocalAuthListMaxLength;                 // 本地授权列表最大长度
    int             SendLocalListMaxLength;                 // 发送本地列表最大长度
}AUTH_LIST_MANAGE;
Q_DECLARE_METATYPE(AUTH_LIST_MANAGE)

typedef struct reservation_profile_info_t {
    bool            ReserveConnectorZeroSupported;          // 支持连接器 0
}RESE_PROFILE;
Q_DECLARE_METATYPE(RESE_PROFILE)

typedef struct smart_charging_profile {
    int             ChargeProfileMaxStackLevel;                 // 充电配置文件最大堆叠级别
    QStringList     ChargingScheduleAllowedChargingRateUnit;    // 允许的充电速率单位
    int             ChargingScheduleMaxPeriods;                 // 充电计划最大周期
    bool            ConnectorSwitch3to1PhaseSupported;          // 支持连接器 3 到 1 相
    int             MaxChargingProfilesInstalled;               // 最大安装充电配置文件
}SMART_CHARGE;
Q_DECLARE_METATYPE(SMART_CHARGE)

typedef struct config_key_info_t {
    CORE_PROFILE        CoreProfile;                            // 核心配置文件
    AUTH_LIST_MANAGE    LocalAuthListManagementProfile;         // 本地授权列表管理配置文件
    RESE_PROFILE        ReservationProfile;                     // 预留配置文件
    SMART_CHARGE        SmartChargingProfile;                   // 智能充电配置文件
}CONFIG_KEY_INFO;
Q_DECLARE_METATYPE(CONFIG_KEY_INFO)

// 充电记录子结构
typedef struct charging_record_info_t {
    int         connector_id;           // 连接器 ID
    int         transactionId;          // 交易 ID
    QString     start_Datetime;         // 开始时间
    QString     end_Datetime;           // 结束时间
    int         start_MeterKWh;         // 开始电表读数
    int         end_MeterKWh;           // 结束电表读数
}CHARGING_RECORD_INFO;
Q_DECLARE_METATYPE(CHARGING_RECORD_INFO)

// 顶层结构体
typedef struct charging_records_info_t {
    int                             count;
    int                             maxLength;
    int                             maxCacheDays;
    QList<charging_record_info_t>   records;
}CHARGING_RECORDS_INFO;
Q_DECLARE_METATYPE(CHARGING_RECORDS_INFO)

// 百富 POS 通讯结构定义
typedef struct pos_request_msg_t {
    QString command;
}REQUEST_MSG;
Q_DECLARE_METATYPE(REQUEST_MSG)

typedef struct pos_request_msg_info_t {
    QString     version;
    REQUEST_MSG request;
}REQUEST_MSG_INFO;
Q_DECLARE_METATYPE(REQUEST_MSG_INFO)

typedef struct pos_get_terminal_info_properties_t {    
    QString responseCode;
    QString responseMessage;
    QString sn;
    QString modelName;
    QString osVersion;
    QString appVersion;
    QString appUpdateTimeStamp;
    QString ipAddress;
}GET_TERMINAL_INFO_PROPERTIES;
Q_DECLARE_METATYPE(GET_TERMINAL_INFO_PROPERTIES)

typedef struct pos_get_terminal_info_response_message_t {
    QString                         command;
    GET_TERMINAL_INFO_PROPERTIES    properties;
}GET_TERMINAL_INFO_RESPONSE_MESSAGE;
Q_DECLARE_METATYPE(GET_TERMINAL_INFO_RESPONSE_MESSAGE)

typedef struct pos_get_terminal_info_response_t {
    QString                             version;
    GET_TERMINAL_INFO_RESPONSE_MESSAGE  response;
}GET_TERMINAL_INFO_RESPONSE;
Q_DECLARE_METATYPE(GET_TERMINAL_INFO_RESPONSE)

typedef struct pos_reboot_properties_t {
    QString responseCode;
    QString responseMessage;
}REBOOT_PROPERTIES;
Q_DECLARE_METATYPE(REBOOT_PROPERTIES)

typedef struct pos_reboot_reponse_message_t {
    QString             command;
    REBOOT_PROPERTIES   properties;
}REBOOT_RESPONSE_MESSAGE;
Q_DECLARE_METATYPE(REBOOT_RESPONSE_MESSAGE)

typedef struct pos_reboot_response_t {
    QString                             version;
    REBOOT_RESPONSE_MESSAGE             response;
}REBOOT_RESPONSE;

typedef REBOOT_RESPONSE RESET_RESPONSE;

typedef struct pos_account_req_info_t {
    QString cardExpireDate;
}ACCOUNT_REQ;
Q_DECLARE_METATYPE(ACCOUNT_REQ)

typedef struct pos_account_rsp_info_t {
    QString expireDate;
    QString cardType;
    QString cardTypeName;
    QString cardUniqueIdentifier;
}ACCOUNT_REP;
Q_DECLARE_METATYPE(ACCOUNT_REP)

typedef struct pos_amount_rsp_info_t {
    QString approvedAmount;
}AMOUNT_RSP;
Q_DECLARE_METATYPE(AMOUNT_RSP)

typedef struct pos_g_configuration_info_t {
    QString name;
    QString value;
}G_CONFIGURATION_INFO;
Q_DECLARE_METATYPE(G_CONFIGURATION_INFO)

typedef struct pos_get_configuration_request_properties_t {
    QString names;
}GET_CONFIGURATION_REQUEST_PROPERTIES;
Q_DECLARE_METATYPE(GET_CONFIGURATION_REQUEST_PROPERTIES)

typedef struct pos_get_configuration_request_message_t {
    QString                                 command;
    GET_CONFIGURATION_REQUEST_PROPERTIES    properties;
}GET_CONFIGURATION_REQUEST_MESSAGE;
Q_DECLARE_METATYPE(GET_CONFIGURATION_REQUEST_MESSAGE)

typedef struct pos_get_configuration_request_message_info_t {
    QString                             version;
    GET_CONFIGURATION_REQUEST_MESSAGE   request;
}GET_CONFIGURATION_REQUEST_MESSAGE_INFO;
Q_DECLARE_METATYPE(GET_CONFIGURATION_REQUEST_MESSAGE_INFO)

typedef struct pos_g_configuration_names_info_t {
    QString preprocessingAmount;
    QString currencyCode;
    QString tapImageName;
    QString tapPromptMsgLine1;
    QString tapPromptMsgLine2;
    QString cardReadSuccessMsg;
    QString displayMode;
    QString detectCardTimeout;
}G_CONFIGURATION_NAMES_INFO;
Q_DECLARE_METATYPE(G_CONFIGURATION_NAMES_INFO)

typedef struct pos_get_configuration_response_message_t {
    QString                     command;
    G_CONFIGURATION_NAMES_INFO  properties;
}GET_CONFIGURATION_RESPONSE_MESSAGE;
Q_DECLARE_METATYPE(GET_CONFIGURATION_RESPONSE_MESSAGE)

typedef struct pos_get_configuration_response_message_info_t {
    QString                             version;
    GET_CONFIGURATION_RESPONSE_MESSAGE  response;
}GET_CONFIGURATION_RESPONSE_MESSAGE_INFO;
Q_DECLARE_METATYPE(GET_CONFIGURATION_RESPONSE_MESSAGE_INFO)

typedef struct pos_host_gateway_info_t {
    QString tokenRequestFlag;
    QString token;
}HOST_GATEWAY;
Q_DECLARE_METATYPE(HOST_GATEWAY)

typedef struct pos_host_rsp_info_t {
    QString token;
}HOST_RSP;
Q_DECLARE_METATYPE(HOST_RSP)

typedef struct pos_s_configuration_info_t {
    QString name;
    QString value;
}S_CONFIGURATION_INFO;
Q_DECLARE_METATYPE(S_CONFIGURATION_INFO)

typedef struct pos_s_configuration_names_info_t {
    QString preprocessingAmount;
    QString tapImageName;
    QString tapPromptMsgLine1;
    QString tapPromptMsgLine2;
    QString cardReadSuccessMsg;
    QString displayMode;
    QString ipAddress;
    QString subnetMask;
    QString defaultGateway;
    QString dnsServer;
    QString backgroundMode;
    QString detectCardTimeout;
}S_CONFIGURATION_NAMES_INFO;
Q_DECLARE_METATYPE(S_CONFIGURATION_NAMES_INFO)

typedef struct pos_trace_info_t {
    QString registerReferenceNumber;
    QString hostReferenceNumber;
}TRACE_INFO;
Q_DECLARE_METATYPE(TRACE_INFO)

// 定义类型映射
typedef QMap<uint32_t, QString> UINT8_QSTRING_MAP;
typedef QMap<uint16_t, QString> UINT16_QSTRING_MAP;
typedef QMap<uint32_t, QString> UINT32_QSTRING_MAP;
typedef QMap<uint64_t, QString> UINT64_QSTRING_MAP;

typedef QMap<int, QVariant> QVARIANTMAP_INT_MAP;

// 注册元类型
Q_DECLARE_METATYPE(UINT8_QSTRING_MAP)

#endif // DATATYPEDEF_H
