/*
  SPDX-FileCopyrightText: 2025-2026 Laurent Montel <montel@kde.org>

  SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "genericnetworkmodelavailableinfo.h"
#include <QJsonObject>

using namespace Qt::Literals::StringLiterals;
GenericNetworkModelAvailableInfo::GenericNetworkModelAvailableInfo() = default;

GenericNetworkModelAvailableInfo::~GenericNetworkModelAvailableInfo() = default;

void GenericNetworkModelAvailableInfo::parseInfo(const QJsonObject &obj)
{
    qDebug() << " obj " << obj;
    if (obj["tools_supported"_L1].toBool()) {
        mCapabilities |= Capability::Tools;
    }
    mDescription = obj["description"_L1].toString();
    mModelName = obj["name"_L1].toString();
    mModelSize = obj["model_size"_L1].toString();
    mIdentifier = obj["id"_L1].toString();
    mOwnedBy = obj["owned_by"_L1].toString();
    if (obj.contains("capabilities"_L1)) {
        parseCapabilities(obj["capabilities"_L1].toObject());
    }
}

void GenericNetworkModelAvailableInfo::parseCapabilities(const QJsonObject &obj)
{
    if (obj["audio"_L1].toBool(false)) {
        mCapabilities |= Capability::Audio;
    }
    if (obj["ocr"_L1].toBool(false)) {
        mCapabilities |= Capability::Ocr;
    }
    if (obj["vision"_L1].toBool(false)) {
        mCapabilities |= Capability::Vision;
    }
    if (obj["function_calling"_L1].toBool(false)) {
        mCapabilities |= Capability::Tools;
    }
    // TODO add more
    // {"audio":false,"classification":false,"completion_chat":false,"completion_fim":false,"fine_tuning":false,"function_calling":false,"moderation":false,"ocr":false,"vision":false}
}

QString GenericNetworkModelAvailableInfo::description() const
{
    return mDescription;
}

void GenericNetworkModelAvailableInfo::setDescription(const QString &newDescription)
{
    mDescription = newDescription;
}

bool GenericNetworkModelAvailableInfo::operator==(const GenericNetworkModelAvailableInfo &other) const
{
    return mDescription == other.description() && mModelName == other.modelName() && mModelSize == other.modelSize() && mIdentifier == other.identifier()
        && mOwnedBy == other.ownedBy() && mCapabilities == other.mCapabilities;
}

QString GenericNetworkModelAvailableInfo::modelName() const
{
    return mModelName;
}

void GenericNetworkModelAvailableInfo::setModelName(const QString &newName)
{
    mModelName = newName;
}

QString GenericNetworkModelAvailableInfo::modelSize() const
{
    return mModelSize;
}

void GenericNetworkModelAvailableInfo::setModelSize(const QString &newModelSize)
{
    mModelSize = newModelSize;
}

QString GenericNetworkModelAvailableInfo::identifier() const
{
    return mIdentifier;
}

void GenericNetworkModelAvailableInfo::setIdentifier(const QString &newIdentifier)
{
    mIdentifier = newIdentifier;
}

QString GenericNetworkModelAvailableInfo::ownedBy() const
{
    return mOwnedBy;
}

void GenericNetworkModelAvailableInfo::setOwnedBy(const QString &newOwnedBy)
{
    mOwnedBy = newOwnedBy;
}

GenericNetworkModelAvailableInfo::Capabilities GenericNetworkModelAvailableInfo::capabilities() const
{
    return mCapabilities;
}

void GenericNetworkModelAvailableInfo::setCapabilities(Capabilities newCapabilities)
{
    mCapabilities = newCapabilities;
}

QDebug operator<<(QDebug d, const GenericNetworkModelAvailableInfo &t)
{
    d.space() << "name:" << t.modelName();
    d.space() << "description:" << t.description();
    d.space() << "modelSize:" << t.modelSize();
    d.space() << "identifier:" << t.identifier();
    d.space() << "ownedBy:" << t.ownedBy();
    d.space() << "capabilities:" << t.capabilities();
    return d;
}

#include "moc_genericnetworkmodelavailableinfo.cpp"
