#ifndef JONTICKET_H
#define JONTICKET_H
#include <QAbstractListModel>
#include <QtQml/qqml.h>

class JobTicket
{
public:
    explicit JobTicket() = default;
    ~JobTicket() = default;
public:
    QString m_machineryIconCharacter = "\uf15c";
    QString m_sopIconCharacter = "\uf292";
    QString m_workstationIcon = "\uf3c5";
    QString m_timeIcon = "\uf1da";
    QString m_workingStatusIcon = "\uf02b";
    QString m_userIconCharacter = "\uf406";

    quint16 m_workId;
    quint16 m_nodeId;
    QString m_orderNo;
    QString m_name;
    QString m_urgencyLevel;
    QString m_completionTime;
    QString m_cancellationTime;
    QString m_cancellationReason;
    QString m_initiatorName;
    QString m_workerUserName;
    QString m_workTime;
    QString m_currentNodeId;
    QString m_currentNodeName;
    QString m_approvalStatus;

    QString m_approvalStatusColor;
};

class JobTicketModel: public QAbstractListModel
{
    Q_OBJECT
    QML_SINGLETON
    QML_NAMED_ELEMENT(JobTicketModel);
public:
    enum JobTicketRoleType {
        MachineryIconCharacter = Qt::UserRole + 1,
        SopIconCharacter,
        WorkStationIcon,
        TimeIcon,
        WorkingStatusIcon,
        UserIconCharacter,

        WorkId,
        NodeId,
        OrderNo,
        Name,
        UrgencyLevel,
        CompletionTime,
        CancellationTime,
        CancellationReason,
        InitiatorName,
        WorkerUserName,
        WorkTime,
        CurrentNodeId,
        CurrentNodeName,
        ApprovalStatus,
        ApprovalStatusColor,
    };
    Q_ENUM(JobTicketRoleType)
private:
    explicit JobTicketModel(QObject *parent=nullptr);
    explicit JobTicketModel() = default;
    ~JobTicketModel();
public:
    static JobTicketModel* pInstance;
    static JobTicketModel* instance();
    static JobTicketModel* create(QQmlEngine*, QJSEngine*);

    void append(const JobTicket& data);
    void clear();

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    
    // 获取"进行中"状态的作业数量
    Q_INVOKABLE int runningCount() const;
    // 获取第一个"进行中"作业的nodeId，如果没有返回-1
    Q_INVOKABLE int getFirstRunningNodeId() const;
    // 获取第一个"进行中"作业的索引，如果没有返回-1
    Q_INVOKABLE int getFirstRunningIndex() const;
    Q_INVOKABLE QVariantMap getSingleJobTicket() const;
    virtual QHash<int, QByteArray> roleNames() const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
private:
    QList<JobTicket> m_dataList;
};
#endif // JONTICKET_H
