//----------------------------------------------------------------------------
///
/// \file   jsonObject.cpp
///
/// \brief  class holding single json object
///
///         each periphery, reference and constructor has an json object
///
/// \date   20230316
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


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


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


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

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

#include "periphery.h"
#include <helpers.h>
#include <QJsonArray>


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


const QString CJsonObject::getAttribute(const QString attr) const
{
   QString empty;

   if( m_object.contains(attr) )
   {
      if( m_object[attr].isArray() )
      {
         return( jsonArrayToString( m_object[attr] ) );
      }
      return( m_object[attr].toString() );
   }

   return( empty );
}


const QStringList CJsonObject::getAttributeList(const QString attr) const
{
   QStringList list;

   if( m_object.contains(attr) )
   {
      if( m_object[attr].isArray() )
      {
         return( jsonArrayToStringList( m_object[attr].toArray() ) );
      }
      list << m_object[attr].toString();
      return( list );
   }

   return( list );
}


bool CJsonObject::attributeSet( const QString attr ) const
{
   QString val=getAttribute( attr );
   if(   ( val == "yes" )
      || ( val == "1" )
      || ( val == "true" )
      || ( val == "YES" ) )
   {
      return( true );
   }

   return( false );
}


//---fin----------------------------------------------------------------------
