#ifndef KYLINCONNECTRESOURCE_H
#define KYLINCONNECTRESOURCE_H

#include <QString>
#include "kylinnetworkresourcemanager.h"
#include "kylinconnectitem.h"
#include "kylinvpnconnectitem.h"
#include "kylinbluetoothconnectitem.h"
#include "kylinnetworkdeviceresource.h"
#include "kylinconnectsetting.h"
#include "kylinapconnectitem.h"

class KyConnectResourse : public QObject
{
    Q_OBJECT
public:
    explicit KyConnectResourse(QObject *parent = nullptr);
    ~KyConnectResourse();

public:
    KyConnectItem *getConnectionItemByUuid(QString connectUuid, bool checkActive = true);
    KyConnectItem *getConnectionItemByUuid(QString connectUuid, QString deviceName);
    void getConnectionList(QString deviceName,
                           NetworkManager::ConnectionSettings::ConnectionType connectionType,
                           QList<KyConnectItem *> &connectItemList);
 //   void getWiredConnections(QList<KyWiredConnectItem *> &wiredConnectItemList);
    void getVpnConnections(QList<KyVpnConnectItem *> &vpnConnectItemList);
    void getBluetoothConnections(QList<KyBluetoothConnectItem *> &bluetoothConnectItemList);
    void getApConnections(QList<KyApConnectItem *> &apConnectItemList);
    KyApConnectItem *getApConnectionByUuid(QString connectUuid);

    void getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting);
    bool getInterfaceByUuid(QString &deviceName, const QString connUuid);
    void getConnectivity(NetworkManager::Connectivity &connectivity);

    bool isWiredConnection(QString uuid);
    bool isWirelessConnection(QString uuid);
    bool isActivatedConnection(QString uuid);
    bool isApConnection(QString uuid);

private:
    bool isActiveDevice(QString conUuid, QString devName);
    KyConnectItem *getConnectionItem(NetworkManager::Connection::Ptr connectPtr, QString devName);
    void getConnectIp(NetworkManager::ConnectionSettings::Ptr settingPtr,
                      QString &ipv4Address,
                      QString &ipv6Address);
//    KyWiredConnectItem *getWiredConnectItem(NetworkManager::Connection::Ptr connectPtr);

    void getVpnConnectData(NetworkManager::ConnectionSettings::Ptr settingPtr,
                           KyVpnConnectItem *vpnItem);
    KyVpnConnectItem *getVpnConnectItem(NetworkManager::Connection::Ptr connectPtr);
    KyBluetoothConnectItem *getBluetoothConnectItem(NetworkManager::Connection::Ptr connectPtr);
    KyApConnectItem *getApConnectItem(NetworkManager::Connection::Ptr connectPtr);

    void getIpv4ConnectSetting(NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
                            KyConnectSetting &connectSetting);
    void getIpv6ConnectSetting(NetworkManager::Ipv6Setting::Ptr &ipv6Setting,
                            KyConnectSetting &connectSetting);

signals:
    void connectionAdd(QString uuid);
    void connectionUpdate(QString uuid);
    void connectionRemove(QString path);
    void connectivityChanged(NetworkManager::Connectivity connectivity);

private:
    KyNetworkResourceManager *m_networkResourceInstance = nullptr;
};
#endif // KYLINCONNECTRESOURCE_H
