/*
  SPDX-FileCopyrightText: 2025-2026 Laurent Montel <montel@kde.org>
  SPDX-FileCopyrightText: 2026 Florian Richer <florian.richer@protonmail.com>

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

#pragma once

#include "core/textautogeneratetextplugin.h"

class LLamaCppSettings;
class QAction;
class LLamaCppPlugin : public TextAutoGenerateText::TextAutoGenerateTextPlugin
{
    Q_OBJECT
public:
    explicit LLamaCppPlugin(TextAutoGenerateText::TextAutoGenerateManager *manager,
                            TextAutoGenerateText::TextAutoGenerateTextInstance *instance,
                            QObject *parent = nullptr);
    ~LLamaCppPlugin() override;

    [[nodiscard]] QString engineName() const override;

    [[nodiscard]] QString translatedPluginName() const override;

    void showConfigureDialog(QWidget *parentWidget) override;

    void load(const KConfigGroup &config) override;
    void save(KConfigGroup &config) override;
    void remove() override;

    [[nodiscard]] QString displayName() const override;
    void setDisplayName(const QString &newName) override;
    [[nodiscard]] QString currentModel() const override;
    void setCurrentModel(const QString &) override;

    [[nodiscard]] TextAutoGenerateText::TextAutoGenerateTextPlugin::EngineType engineType() const override;

    [[nodiscard]] bool hasVisionSupport() const override;
    [[nodiscard]] bool hasToolsSupport() const override;
    [[nodiscard]] bool hasOcrSupport() const override;
    [[nodiscard]] bool hasAudioSupport() const override;
    [[nodiscard]] bool hasThinkSupport() const override;
    [[nodiscard]] QString shareNamePrompt() const override;

    [[nodiscard]] QString passwordServiceName() const;

    [[nodiscard]] ActivateInstanceActionInfo activateInstanceAction() override;

    void askToAssistant(const QString &msg) override;

protected:
    void sendToAssistant(const SendToAssistantInfo &info) override;

Q_SIGNALS:
    void loadApiKeyDone();

private:
    void removeApiKey();
    void loadApiKey();
    void slotLMStudioRequested();
    void slotLMStudioFailed(const QString &errorStr);
    void slotLMStudioStarted();
    void slotDownloadLMStudio();
    LLamaCppSettings *const mLLamaCppSettings;
    // LMStudioManager *const mLMStudioManager;
    QAction *mCurrentAction = nullptr;
};
