#ifndef WRITINGTONELISTMODEL_H
#define WRITINGTONELISTMODEL_H

#include <QObject>
#include <QAbstractListModel>
#include <ukui-log4qt.h>
#include "../global/tonestylemanager.h"

class WritingToneListModel : public QAbstractListModel
{
    Q_OBJECT
public:
    enum WritingToneRoleType {
        ToneUuid = Qt::UserRole + 1,
        ToneName,
        ToneOriginal,
        ToneTarget,
        ToneInstruction,
        IsCustom,
        FileURL
    };
    Q_ENUM(WritingToneRoleType)

    explicit WritingToneListModel(QObject *parent = nullptr);
    static WritingToneListModel *getInstance();

    // QAbstractListModel interface
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QHash<int, QByteArray> roleNames() const override;

    // 数据操作接口
    Q_INVOKABLE bool addTone(const ToneStyle &info);
    Q_INVOKABLE bool removeTone(const QString &uuid);
    Q_INVOKABLE bool updateTone(const QString& uuid, const ToneStyle& newData);
    Q_INVOKABLE QVariantMap getTone(const QString &uuid) const;
    Q_INVOKABLE QVariantMap getToneByIndex(int index) const;
    Q_INVOKABLE int toneCount() const;
    Q_INVOKABLE bool isCustomTone(const QString& uuid) const;

signals:
    void toneAdded(const ToneStyle& newTone);
    void toneRemoved(const QString& uuid);
    void toneUpdated(const ToneStyle& updatedTone);

private slots:
    void onToneStyleAdded(const ToneStyle &newToneStyle);
    void onToneStyleRemoved(const QString &uuid);
    void onToneStyleUpdated(const ToneStyle &updatedToneStyle);

private:
    void loadTones();
    int findToneIndex(const QString &uuid) const;
    bool isToneCustom(const ToneStyle& toneStyle) const;

    QVector<ToneStyle> m_tones;
    ToneStyleManager *m_toneManager;
    static WritingToneListModel *mInstance;
};

#endif // WRITINGTONELISTMODEL_H
