#ifndef KAMODELSETTINGPAGE_H
#define KAMODELSETTINGPAGE_H

#include <memory>
#include <kdialog.h>

#include <QWidget>

#include "kamodelitem.h"

using namespace std;
using namespace kdk;

typedef struct {
    RemoteModelVendorId modelVendorId;
    RemoteModelId modelTypeId;
    QString apiKey;
    QString secretKey;
} S_Model;

class KAModelSettingDialog : public KDialog
{
    Q_OBJECT
public:
    explicit KAModelSettingDialog(S_Model model, QWidget *parent = nullptr);
    explicit KAModelSettingDialog(QWidget *parent = nullptr);
    ~KAModelSettingDialog();

private:
    void initLayout();
    void initUIData();

    QString modelVendorToString(const RemoteModelVendorId &vid);
    QString modelTypeToString(const RemoteModelId &vid);

    void accept() override;

private slots:
    void updatePasswordEdit(int index);
    void updateModelTypeCombobox();
    void switchButtonState();
    void switchButtonStateEditing1();
    void switchButtonStateEditing2();

private:
    class Private;
    shared_ptr<Private> d_ptr;
};

class KAModelSettingPage : public QWidget
{
    Q_OBJECT
    friend class KAModelSettingDialog;
public:
    explicit KAModelSettingPage(QWidget *parent = nullptr);
    ~KAModelSettingPage();

    void addItem(RemoteModelId type);
    bool deleteModel(RemoteModelId &type);

signals:
    void sigDelete(RemoteModelId type);

private slots:
    void editModel(RemoteModelId &type);
    void addModel();

private:
    void initLayout();
    void reinitLayout();
    void initAddButton();
    void initConfig();
    void loadOneModel(int mvid, int mtid, QJsonObject obj);

private:
    class Private;
    shared_ptr<Private> d_ptr;
};

#endif // KAMODELSETTINGPAGE_H
