#ifndef NETWORK_DEVICE_DETECTOR_H
#define NETWORK_DEVICE_DETECTOR_H

#include <QObject>

#include "device_information.h"

enum class DetectResult : int
{
    DETECT_OK = 0,
    DETECT_ERROR,
};

enum class SetResult : int
{
    SET_OK = 0,
    SET_ERROR,
};

class NetworkDeviceDetector: public QObject
{
    Q_OBJECT
public:
    static NetworkDeviceDetector *getInstance();
    ~NetworkDeviceDetector();
    static QList<DeviceInformation> getDeviceInfoFromHost(const QString &host, const int port, ProtocolType protocolType);
private:
    NetworkDeviceDetector();
    QMap<QString, DeviceInformation> m_mpDevInfo;

    /**
     * @brief 通过分析DeviceInformation中的已有信息检测信息，
     *        并写入DeviceInformation
     * 
     * @return DetectResult 
     */
    DetectResult detectHost           (DeviceInformation &);
    DetectResult detectNetWorkNode    (DeviceInformation &);
    DetectResult detectUri            (DeviceInformation &);
    DetectResult detectProtocolType   (DeviceInformation &);
    DetectResult detectVendorAndModel (DeviceInformation &);
    
    DetectResult detectUUID           (DeviceInformation &);
    DetectResult detectSerial         (DeviceInformation &);

    SetResult setNetWorkNode          (DeviceInformation &);
    SetResult setUri                  (DeviceInformation &, 
                                       const ProtocolType &);
    SetResult setName                 (DeviceInformation &);

    DeviceInformation newDeviceGet(DeviceInformation &);

    void lpinfoPreSet(const QString &uri);
    void zconfPreSet(QString name);

    bool probe(DeviceInformation &deviceInfo, const QString host, const int port, ProtocolType protocolType);
    bool probeIpp(QList<DeviceInformation> &deviceInfoList, const QString host, const int port);
signals:
    void autoDetectStart();
    void newDeviceSend(DeviceInformation &);
    void setHostFromDetect(const QString &);
};

#endif // NETWORK_DEVICE_DETECTOR_H