#ifndef FLASHTARGET_H
#define FLASHTARGET_H

#include <QString>
#include <QStringList>
#include <QList>
#include <QTreeWidgetItem>

#define fileNameTarget  "targets.ini"

#define AESA_RFIF_MODEL "2"   //id model for aesa rfif firmware

struct modelItem
{
    QString g;                              //group in file ini
    QString idModel;
    QString model;
    QString description;
    unsigned int type;                      //0 128 mbit, 1 256 mbit (32 Mbytes = 256 mbit)
    unsigned int byte3_4;                   //0 for 3 bytes address, 1 for 4 bytes address
    unsigned int numSector;                 //128, 256
    QString goldenAddressStartArea;
    QString goldenAddressStopArea;
    QString userAddressStartArea;
    QString userAddressStopArea;
    QString testAddress;
};

struct targetItem
{
    QString g;                              //group in file ini
    QString idTgt;
    QString description;
    QString slotAddress;
    QString arch;
    QString name;
    QString filePrefix;
    QString idModel;

    modelItem model;

    QTreeWidgetItem* wi;
};



class flashTargetClass
{
public:
    static flashTargetClass *instance();

    targetItem getTarget(unsigned int _idx);

    QStringList getInfoLists();

    bool readTargets();

    QString getDefIp();

    unsigned int getDefPort();

    QString getDefTarget();

    unsigned int countTarget();

    unsigned int countModel();

    const targetItem* getFromName(const QString& fname);

private:

    static flashTargetClass* s_instance;
    flashTargetClass();

    ~flashTargetClass();

    bool writeTargets();

    QList<targetItem> listTargets;
    QList<modelItem> listModels;

    QString target_filedb;

    QString def_ip;
    unsigned int def_port;
    QString def_target;

    bool copyDataFromModel(modelItem * _model, QString _idModel);

    modelItem* getModel(QString _idModel);

};

#endif // FLASHTARGET_H
