// src/stellarmatedevice.h
#ifndef STELLARMATEDEVICE_H
#define STELLARMATEDEVICE_H

#include <QObject>
#include <QString>
#include <qqml.h>

class StellarMateDevice : public QObject
{
        Q_OBJECT
        // QML_ELEMENT removed as it might conflict with manual registration in main.cpp

        Q_PROPERTY(QString ipAddress READ ipAddress WRITE setIpAddress NOTIFY ipAddressChanged)
        Q_PROPERTY(QString hostname READ hostname WRITE setHostname NOTIFY hostnameChanged)
        Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY versionChanged)
        Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
        Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged)
        Q_PROPERTY(bool isLocal READ isLocal WRITE setIsLocal NOTIFY isLocalChanged)

    public:
        explicit StellarMateDevice(QObject *parent = nullptr);
        StellarMateDevice(const StellarMateDevice &other);
        StellarMateDevice &operator=(const StellarMateDevice &other);

        // Getters
        QString ipAddress() const
        {
            return m_ipAddress;
        }
        QString hostname() const
        {
            return m_hostname;
        }
        QString version() const
        {
            return m_version;
        }
        QString model() const
        {
            return m_model;
        }
        QString machineId() const { return m_machineId; }
        void setMachineId(const QString &machineId) { m_machineId = machineId; }
        bool isOnline() const
        {
            return m_isOnline;
        }
        bool isLocal() const
        {
            return m_isLocal;
        }

        // Setters
        void setIpAddress(const QString &ipAddress);
        void setHostname(const QString &hostname);
        void setVersion(const QString &version);
        void setModel(const QString &model);
        void setIsOnline(bool isOnline);
        void setIsLocal(bool isLocal);

        // Static method to detect if running on local device
        static bool detectLocalDevice();

         QStringList secondaryIpAddresses() const { return m_secondaryIps; }
    void addSecondaryIp(const QString &ip) {
        if (!m_secondaryIps.contains(ip) && ip != m_ipAddress) {
            m_secondaryIps.append(ip);
            emit secondaryIpsChanged();
        }
    }
    void setSecondaryIpAddresses(const QStringList &ips) {
        m_secondaryIps.clear();
        for (const QString &ip : ips) {
            if (!m_secondaryIps.contains(ip) && ip != m_ipAddress) {
                m_secondaryIps.append(ip);
            }
        }
        emit secondaryIpsChanged();
    }
    
    QStringList allIpAddresses() const {
        QStringList all;
        all << m_ipAddress;
        all << m_secondaryIps;
        return all;
    }

    bool hasIpAddress(const QString &ip) const {
    return m_ipAddress == ip || m_secondaryIps.contains(ip);
}

    signals:
        void ipAddressChanged();
        void hostnameChanged();
        void versionChanged();
        void modelChanged();
        void isOnlineChanged();
        void isLocalChanged();      
        void secondaryIpsChanged();


    private:
        QString m_ipAddress;
        QStringList m_secondaryIps;
        QString m_hostname;
        QString m_version;
        QString m_model;
        QString m_machineId;
        bool m_isOnline;
        bool m_isLocal;
};

#endif // STELLARMATEDEVICE_H
