// SPDX-License-Identifier: GPL-3.0-or-later

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (C) 2013 - 2024, nymea GmbH
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
*
* This file is part of nymea-energy-plugin-nymea.
*
* nymea-energy-plugin-nymea.s free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nymea-energy-plugin-nymea.s distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with nymea-energy-plugin-nymea. If not, see <https://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "chargingstate.h"

ChargingState::ChargingState(const ThingId &evChargerId)
    : m_evChargerId{evChargerId}
{

}

ThingId ChargingState::evChargerId() const
{
    return m_evChargerId;
}

void ChargingState::setEvChargerId(const ThingId &evChargerId)
{
    m_evChargerId = evChargerId;
}

void ChargingState::setMode(Mode mode)
{
    m_mode = mode;
}

ChargingState::Mode ChargingState::mode() const
{
    return m_mode;
}

bool ChargingState::overloadProtectionActive() const
{
    return m_overloadProtectionActive;
}

void ChargingState::setOverloadProtectionActive(bool overloadProtectionActive)
{
    m_overloadProtectionActive = overloadProtectionActive;
}

int ChargingState::targetTimeOvershot() const
{
    return m_targetTimeOvershot;
}

void ChargingState::setTargetTimeOvershot(int targetTimeOvershot)
{
    m_targetTimeOvershot = targetTimeOvershot;
}

bool ChargingState::chargingTargetUnreachable() const
{
    return m_chargingTargetUnreachable;
}

void ChargingState::setChargingTargetUnreachable(bool chargingTargetUnreachable)
{
    m_chargingTargetUnreachable = chargingTargetUnreachable;
}

bool ChargingState::targetPercentageReached() const
{
    return m_targetPercentageReached;
}

void ChargingState::setTargetPercentageReached(bool targetPercentageReached)
{
    m_targetPercentageReached = targetPercentageReached;
}

int ChargingState::powerLockSeconds() const
{
    return m_powerLockSeconds;
}

void ChargingState::setPowerLockSeconds(int powerLockSeconds)
{
    m_powerLockSeconds = powerLockSeconds;
}

int ChargingState::powerLockDuration() const
{
    return m_powerLockDuration;
}

void ChargingState::setPowerLockDuration(int powerLockDuration)
{
    m_powerLockDuration = powerLockDuration;
}

bool ChargingState::batteryLevelConsiderationActive() const
{
    return m_batteryLevelConsiderationActive;
}

void ChargingState::setBatteryLevelConsiderationActive(bool batteryLevelConsiderationActive)
{
    m_batteryLevelConsiderationActive = batteryLevelConsiderationActive;
}

bool ChargingState::operator==(const ChargingState &other) const
{
    return m_evChargerId == other.evChargerId() &&
           m_mode == other.mode() &&
           m_overloadProtectionActive == other.overloadProtectionActive() &&
           m_targetTimeOvershot == other.targetTimeOvershot() &&
           m_chargingTargetUnreachable == other.chargingTargetUnreachable() &&
           m_chargingTargetUnreachable == other.chargingTargetUnreachable() &&
           m_targetPercentageReached == other.targetPercentageReached() &&
           m_powerLockSeconds == other.powerLockSeconds() &&
           m_powerLockDuration == other.powerLockDuration() &&
           m_batteryLevelConsiderationActive == other.batteryLevelConsiderationActive();

}

bool ChargingState::operator!=(const ChargingState &other) const
{
    return !(*this == other);
}

QDebug operator<<(QDebug debug, const ChargingState &chargingState)
{
    const QDebugStateSaver saver(debug);
    debug.nospace().noquote() << "ChargingState: Charger: " << chargingState.evChargerId().toString() << ", ";
    debug.nospace().noquote() << "Mode: " << chargingState.mode() << ", ";
    debug.nospace().noquote() << "Overload protection active: " << chargingState.overloadProtectionActive() << ", ";
    debug.nospace().noquote() << "Target time overshot: " << chargingState.targetTimeOvershot() << " [s], ";
    debug.nospace().noquote() << "Target percentage reached: " << chargingState.targetPercentageReached() << " [s], ";
    debug.nospace().noquote() << "Power lock: " << chargingState.powerLockSeconds() << " / " << chargingState.powerLockDuration() << " [s], ";
    debug.nospace().noquote() << "Battery level consideration active: " << chargingState.batteryLevelConsiderationActive();
    return debug;
}

ChargingStates::ChargingStates()
{

}

ChargingStates::ChargingStates(const QList<ChargingState> &other)
    : QList<ChargingState>{other}
{

}

QVariant ChargingStates::get(int index) const
{
    return QVariant::fromValue(at(index));
}

void ChargingStates::put(const QVariant &variant)
{
    append(variant.value<ChargingState>());
}
