#ifndef _PINMUX_APP_H_
#define _PINMUX_APP_H_
//----------------------------------------------------------------------------
///
/// \file   app.h
///
/// \brief  See implementation for further details
///
/// \date   20180201
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Documentation------------------------------------------------------------


//---Includes -----------------------------------------------------------------


//---General--------------------------

#include <QString>
#include <QMap>
#include <QList>
#include <QJsonObject>

//---Own------------------------------

#include "periphery.h"
#include "board.h"
#include "path.h"
#include "variant.hpp"


//--- Declaration -------------------------------------------------------------


class CApp: public CPath
{
private:
   //QMap<QString, QList<CPeriphery>> map;
public:
   //QList<CPeriphery> list;
   //QMap<QString, CReference> peripheryMap;
   QList<CReference> referenceList;
   QMap<QString, QString> SymbolMap;
   QString name;
   QString id;
   QString debugUart;
   bool heartbeat;
   QString boardName;
   QString boardId;
   QStringList symbolMapList;
   CVariant m_variant;
   QStringList m_path;
   QVariantMap m_properties;
   QString m_mainFile;
   QStringList m_options;

public:
   CApp()
      :heartbeat(false)
   {  };
   void setBoardName(const QString &_boardName)
   {
      boardName=_boardName;
   }
   void setBoardId(const QString &_boardId)
   {
      boardId=_boardId;
   }
   int parseJson(const QJsonObject &jsonObject);
   bool loadFile(const QString &fileName);
   bool loadByteArray(const QByteArray &array, const QString &fileName);
   void dump() const;
   void dumpPinmux();
   const QString &getName() const { return(name); }
   const QString &getId() const { return(id); }
   const QString &getDebugUart() const
   {
      return(debugUart);
   };
   QList<CReference> &getReferenceList()
   {
      return(referenceList);
   }
   const QList<CReference> &getConstReferenceList() const
   {
      return(referenceList);
   }
   bool getHeartbeat() const
   {
      return(heartbeat);
   }
   void clear()
   {
      referenceList.clear();
   }
   const CVariant& getVariant() const { return(m_variant); }
   void setVariant(const QString& variant) { m_variant.set(variant); }

   void loadProperties(const QJsonObject &jsonObject);
   const QVariantMap &getProperties() const
   {
      return(m_properties);
   }
   CReferencePtr findReferenceByName(const QString name)
   {
      CReferencePtr ptr;
      for( auto &ref : getReferenceList() )
      {
         if( ref.getName() == name )
         {
            ptr=&ref;
            return(ptr);
         }
      }
      return(ptr);
   }
   void setMainFile( const QString &file)
   {
      m_mainFile=file;
   };
   const QString &getMainFile( ) const
   {
      return(m_mainFile);
   };
   void setOptions( const QStringList &options )
   {
      m_options=options;
   }
   const QStringList &getOptions(  ) const
   {
      return( m_options );
   }
};


//---fin----------------------------------------------------------------------
#endif // ? ! _PINMUX_APP_H_
