#ifndef GENERALINTERFACE_H
#define GENERALINTERFACE_H

#include "DataTypeDef.h"
#include <QByteArray>
#include <QtEndian>
#include <QLabel>

#include <QPushButton>
#include <QPalette>
#include <QLineEdit>

class GeneralInterface {
public:
    // 安全转换函数
    template<typename T>
    static T toInt(const QByteArray &data,
                   int offset = 0,
                   bool networkOrder = true);

    // 便捷方法
    static uint8_t toUInt8(const QByteArray &data, int offset = 0);

    static uint16_t toUInt16(const QByteArray &data,
                             int offset = 0,
                             bool networkOrder = true);

    static uint32_t toUInt32(const QByteArray &data,
                             int offset = 0,
                             bool networkOrder = true);

    static uint64_t toUInt64(const QByteArray &data,
                             int offset = 0,
                             bool networkOrder = true);


    // 数据类型转换
    template<typename T>
    static QByteArray encodeValue(T& data, const uint8_t& length);

    template<typename T>
    static T decodeValue(const QByteArray& data);

    static QByteArray networkStructToByteArray(const MSG_HEAD& data);

    static QByteArray encodeChargeCtlInfo(const CHARGE_CTL_INFO& data);

    static charge_gun_basic_info_t decodeChargeBasicInfo(const QByteArray& data);

    static charge_gun_charge_info_t decodeChargeInfo(const QByteArray& data);

    static ccu_reply_info_t decodeReplyInfo(const QByteArray& data);

    static QString formatMillisecondDifference(qint64 ms1, qint64 ms2);

    static QMap<uint32_t, BASIC_INFO> m_gun_basic_info;

    static void makeLabelJump(QLabel *label);

    static QString getGunIconUrl(const uint8_t& type, bool isError = false);

    /**
     * @brief FormStandby::isError  判断是否存在大于最大错误码的报警信息
     * @param error_list            错误码索引列表
     * @return                      存在返回TRUE，否则返回FALSE
     */
    static bool isError(const QList<uint8_t> &error_list);

    static uint8_t getMaxElement(const QList<uint8_t> &state_list);

    static void setButtonBackground(QPushButton* button, const QString& imageUrl);

    static void setLineeditBackground(QLineEdit* lineEdit, const QString& imageUrl);

    static void addRotationAnimation(QLabel* label);

    static uint8_t getMaxElementWithQMax(const QList<uint8_t> &list);
};


#endif // GENERALINTERFACE_H
