// src/stellarmatedevice.cpp
#include "stellarmatedevice.h"
#include <QFile>

StellarMateDevice::StellarMateDevice(QObject *parent)
    : QObject(parent)
    , m_isOnline(false)
    , m_isLocal(false)
{
}

StellarMateDevice::StellarMateDevice(const StellarMateDevice &other)
    : QObject(other.parent())
    , m_ipAddress(other.m_ipAddress)
    , m_secondaryIps(other.m_secondaryIps) 
    , m_hostname(other.m_hostname)
    , m_version(other.m_version)
    , m_model(other.m_model)
    , m_isOnline(other.m_isOnline)
    , m_isLocal(other.m_isLocal)
{
}

StellarMateDevice &StellarMateDevice::operator=(const StellarMateDevice &other)
{
    if (this != &other)
    {
        setIpAddress(other.m_ipAddress);
        m_secondaryIps = other.m_secondaryIps;
        emit secondaryIpsChanged();   
        setHostname(other.m_hostname);
        setVersion(other.m_version);
        setModel(other.m_model);
        setIsOnline(other.m_isOnline);
        setIsLocal(other.m_isLocal);
    }
    return *this;
}

void StellarMateDevice::setIpAddress(const QString &ipAddress)
{
    if (m_ipAddress != ipAddress)
    {
        m_ipAddress = ipAddress;
        emit ipAddressChanged();
    }
}

void StellarMateDevice::setHostname(const QString &hostname)
{
    if (m_hostname != hostname)
    {
        m_hostname = hostname;
        emit hostnameChanged();
    }
}

void StellarMateDevice::setVersion(const QString &version)
{
    if (m_version != version)
    {
        m_version = version;
        emit versionChanged();
    }
}

void StellarMateDevice::setModel(const QString &model)
{
    if (m_model != model)
    {
        m_model = model;
        emit modelChanged();
    }
}

void StellarMateDevice::setIsOnline(bool isOnline)
{
    if (m_isOnline != isOnline)
    {
        m_isOnline = isOnline;
        emit isOnlineChanged();
    }
}

void StellarMateDevice::setIsLocal(bool isLocal)
{
    if (m_isLocal != isLocal)
    {
        m_isLocal = isLocal;
        emit isLocalChanged();
    }
}

bool StellarMateDevice::detectLocalDevice()
{
    // Check if the local StellarMate model file exists
    QFile modelFile("/etc/stellarmate/model");
    return modelFile.exists();
}
