#include "modelcallpriority.h"

#include <ukui-log4qt.h>

#include <QHBoxLayout>
#include <QLabel>

using namespace kyai::config::model;

ModelCallPriority::ModelCallPriority(QWidget *parent) : QWidget(parent) {
    m_modelCallPriorityLabel = new QLabel(tr("Model call priority"), parent);
    m_modelCallPriorityLabel->setAccessibleName("kylin-ai-subsystem-modelconfig_QLabel_modelCallPriorityLabel");

    m_modelPriorityComboBox = new QComboBox(parent);
    m_modelPriorityComboBox->setAccessibleName("kylin-ai-subsystem-modelconfig_QComboBox_m_modelCallPriorityLabel");
    m_modelPriorityComboBox->setFixedSize(410, 36);

    m_modelPriorityComboBox->addItem(tr("Cloud model first (Kylin Certification)"));
    m_modelPriorityComboBox->addItem(tr("Local model first (Kylin Certification)"));
    m_modelPriorityComboBox->addItem(tr("Private model first"));

    QHBoxLayout *modelCellPriLayout = new QHBoxLayout();
    modelCellPriLayout->setContentsMargins(16, 0, 16, 0);

    modelCellPriLayout->addWidget(m_modelCallPriorityLabel);
    modelCellPriLayout->addStretch();
    modelCellPriLayout->addWidget(m_modelPriorityComboBox);

    parent->setLayout(modelCellPriLayout);

    initConnections();
}

void ModelCallPriority::setModelCallPriority(kyai::config::model::DeployType deployType) {
    if (deployType == DeployType::PublicCloud) {
        m_modelPriorityComboBox->setCurrentIndex(0);
    } else if (deployType == DeployType::Ondevice) {
        m_modelPriorityComboBox->setCurrentIndex(1);
    } else if (deployType == DeployType::Custom) {
        m_modelPriorityComboBox->setCurrentIndex(2);
    }
}

void ModelCallPriority::initConnections() {
    connect(m_modelPriorityComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(modelPriorityChanged(int)));
}

void ModelCallPriority::modelPriorityChanged(int index) {
    DeployType type = DeployType::PublicCloud;
    if (index == 0) {
        type = DeployType::PublicCloud;
    } else if (index == 1) {
        type = DeployType::Ondevice;
    } else if (index == 2) {
        type = DeployType::Custom;
    }
    emit topModelPriorityChanged(type);
}
