/*
 * Copyright (C) 2020, KylinSoft Co., Ltd.
 *
 * This program is 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.
 *
 * This program is 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 this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#ifndef COMMANDTEMPLATELIST_H
#define COMMANDTEMPLATELIST_H

#include <QAbstractListModel>
#include <QObject>

#include <kylin-ai/private/osassistant/osassistant.h>
#include <ukui-log4qt.h>

#include "global/kaglobal.h"

using namespace kyai::assistant;

// sdk提示词类型
//enum PromptContentAccessType {
//    ReadOnly = 1,   // 预设的提示词——文本扩写、文本润色、中英互译、内容校对、总结概括，仅支持查看不可修改内容
//    ReadWrite,      // 自定义提示词
//    NoAccess        // 预设提示词——系统助手、生成代办、整理周报、新建日程，不可进行提示词查看
//};

typedef struct {
//    int index;
    int actorId;
    QString name;
    QString content;
    PromptContentAccessType commandType;
    QString iconPath;
} CommandTemplateItem;

class CommandTemplateList : public QAbstractListModel
{
    Q_OBJECT
public:

    enum CommandTemplateRoleType {
        NameRole = Qt::UserRole+1,
        ActorRole,
        ContentRole,
        CommandTypeRole,
        IconRole
    };

    Q_ENUM(CommandTemplateRoleType)

    explicit CommandTemplateList(QObject *parent = nullptr);
//    static CommandTemplateList *getInstance();
    static CommandTemplateList *originalCommandListModel;


    int rowCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    QHash<int, QByteArray> roleNames() const;

    QList<CommandTemplateItem> getCommandTemplateList();
    Q_INVOKABLE QVariant getData(const int row,int role) const;
    int getPromptId(QString name);
    Q_INVOKABLE int count();

    void createCommand(const QString &name, const QString &content);
    void updateCommand(int actorId, const QString &name, const QString &content);
    Q_INVOKABLE void moveCommand(const int fromIndex,const int toIndex);

    void initData(std::vector<Prompt> promptList);
    void loadData(QList<CommandTemplateItem> commandTemplateList);
    void resetAllData();
    void addData(PromptContentAccessType commandType, int actorId, const QString &name, const QString &content);
    void updateData(int actorId, const QString &name, const QString &content);

public slots:
    void deleteCommand(int actorId, const QString &name);
    void removeData(int actorId, const QString &name);


signals:
    void sigCreateCommand(QString name, QString content);
    void sigUpdateCommand(int actorId, QString name, QString content);
    void sigUpdateUI();

    // 更新qml主页选中提示词
    void sigUpdateActiveCommand(int actorId, QString name);
    void sigDeleteActiveCommand(int actorId, QString name);

private:
//    static CommandTemplateList *m_commandTemplateListModel;
    QList<CommandTemplateItem> m_commandTemplateList;
};

#endif // COMMANDTEMPLATELIST_H
