#ifndef STANDARD_H
#define STANDARD_H

#include <QObject>
#include <QString>
#include <QJsonObject>
#include <QMap>

#define MAX_STANDARD_ITEM  (8)
#define MAX_STANDARD_NUM   (8)

class StandardItem
{
public:
   int oilcompartment_volume;   // L per unit
   double system_threshold;      //Kpa
   double valve_threshold;       //Kpa
};


class Standard
{
public:
    QString standard_name;
    double positive_target;
    double negative_target;
    int interval_time; // s
    int item_count;
    StandardItem  item[MAX_STANDARD_ITEM];
};



class StandardManager: public QObject
{
    Q_OBJECT
public:
    static StandardManager* instance();
    ~StandardManager();

    bool getStandard(const QString& name, Standard& standard);
    //void addStandard(const Standard& standard);
    //void removeStandard(const QString& name);

    Q_INVOKABLE void init();
    //Q_INVOKABLE int getcount();
    Q_INVOKABLE QJsonObject get_names();
    Q_INVOKABLE QJsonObject get_standard(const QString name);
    //add or modify
    Q_INVOKABLE bool add_standard(const QString& jsonStr );
    //remove
    Q_INVOKABLE void remove_standard(const QString name);


private:
    explicit StandardManager(QObject* parent = nullptr);
    std::vector<Standard>  m_standard;
    //QMap<QString, QJsonObject> m_standardMap;
    void add_GB();
    void load_standards();
    void save_standards();

};

#define g_StandardManager  StandardManager::instance()


#endif // STANDARD_H
