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


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


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

#include "peripheryTrivia.h"

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

//#include <qt5/QtCore/QString>
//#include <QList>
//#include <QMap>
//#include <QRandomGenerator>
#include "reference.h"
#include "pointer.h"


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


class CReference: public CPeripheryTrivia
{
private:
   QString m_predefined;
   QString m_requiredAttribute;
   CPeripheryPtr m_pPeriferyLink;
   CPeripheryPtr m_pParent;
   QString m_alternateFunction;

public:
   CReference(const QString &name, const  QString &type
              , const  QString &periphery={}
         , const  QString &Relation={} )
      :CPeripheryTrivia(name, type, periphery, Relation)
      ,m_pPeriferyLink(nullptr)
   {
   }
   const bool getUseIrq() const
   {
      QString attribute=getAttribute("noIrqs");
      return( ! ( (attribute=="yes")
               ||   (attribute=="YES")
               ||   (attribute=="1")
               ||   (attribute=="true")
                  )
             );
   }

   const QString &setPredefined(const QString &predefined)
   {
      m_predefined=predefined;
      return(m_predefined);
   }
   const QString &getPredefined() const
   {
      return(m_predefined);
   }

   const QString &setRequiredAttribute(const QString &requiredAttribute)
   {
      m_requiredAttribute=requiredAttribute;
      return(m_requiredAttribute);
   }
   const QString &getRequiredAttribute() const
   {
      return(m_requiredAttribute);
   }
   const QString &setAlternateFunction(const QString &alternateFunction)
   {
      return(m_alternateFunction=alternateFunction);
   }
   const QString &getAlternateFunction() const
   {
      return(m_alternateFunction);
   }
   //const QString getWiring() const;
   virtual QString printable() const;
   void setPeripheryLink(CPeripheryPtr link);
   CPeripheryPtr getPeripheryLink() const
   {
      return(m_pPeriferyLink);
   }
   virtual void dump() const override;
   //EBinding getBinding() const;
   void unReserve();

   /** \brief  link with an periphery
    *
    *          if periphery is not already link, link it back to the reference
    *          also.
    **/
   void link(CPeripheryPtr periphery);
   CPeripheryPtr getParent() const
   {
      return(m_pParent);
   }
   void setParent(CPeripheryPtr parent)
   {
      m_pParent=parent;
   }

   bool isExclusive() const;
   bool parseJSON(const QJsonObject &object, const QString boardId);
};


//---fin----------------------------------------------------------------------
#endif // ? ! ARENA_PINMUX_REFERENCE_H
