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

   SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "kaichatconfiguremcpserverswidget.h"
#include <QVBoxLayout>
#include <TextAutoGenerateText/TextAutoGenerateManager>
#include <TextAutoGenerateTextMcpProtocolCore/McpServerManager>
#include <TextAutoGenerateTextMcpProtocolWidgets/McpServerWidget>

using namespace Qt::Literals::StringLiterals;
KAIChatConfigureMcpServersWidget::KAIChatConfigureMcpServersWidget(TextAutoGenerateText::TextAutoGenerateManager *manager, QWidget *parent)
    : QWidget{parent}
    , mMcpServerWidget(new TextAutoGenerateTextMcpProtocolWidgets::McpServerWidget(manager->textAutoGenerateTextMcpServerManager()->mcpServerModel(), this))
    , mManager(manager)
{
    auto mainLayout = new QVBoxLayout(this);
    mainLayout->setObjectName(u"mainLayout"_s);
    mainLayout->setContentsMargins({});

    mMcpServerWidget->setObjectName(u"mMcpServerWidget"_s);
    mainLayout->addWidget(mMcpServerWidget);
    connect(mMcpServerWidget, &TextAutoGenerateTextMcpProtocolWidgets::McpServerWidget::settingsChanged, this, &KAIChatConfigureMcpServersWidget::save);
    load();
}

KAIChatConfigureMcpServersWidget::~KAIChatConfigureMcpServersWidget() = default;

void KAIChatConfigureMcpServersWidget::save()
{
    mManager->textAutoGenerateTextMcpServerManager()->saveServers();
}

void KAIChatConfigureMcpServersWidget::load()
{
    mManager->textAutoGenerateTextMcpServerManager()->loadServers();
}

void KAIChatConfigureMcpServersWidget::restoreToDefaults()
{
    // nothing
}

#include "moc_kaichatconfiguremcpserverswidget.cpp"
