#include "PropertyInternal.h"
#include "Log.h"
#include "GroupPropertyInternal.h"

namespace NDTS
{
	namespace SCO
	{
	PropertyInternal::PropertyInternal(char *pShortName, char *pLongName, int flags)
	{
		pLog = new Log();
		this->pShortName = pShortName;
		this->pLongName = pLongName;
		this->flags = flags;
		pParent = 0;
		isInitComplete = false;
		this->pBackPointer = 0;
	}

	PropertyInternal::~PropertyInternal(void)
	{
		delete pLog;
	}

	void PropertyInternal::initComplete(void)
	{
		isInitComplete = true;
	}

	const char *PropertyInternal::getShortName()
	{
		return pShortName;
	}

	const char *PropertyInternal::getLongName()
	{
		return pLongName;
	}


	int PropertyInternal::getFlags()
	{
		return flags;
	}

	bool PropertyInternal::updateFlags(int newFlags)
	{
		if (newFlags == flags)
			return false;

		flags = newFlags;
		createChangeItem(CTPropertyFlags);
		pLog->addMessageToLog(NDTS_LLDebug, "%s Flags changed to %d", pShortName, flags);
		return true;
	}
	void PropertyInternal::setBackPointer(void *pBackPointer)
	{
		this->pBackPointer = pBackPointer;
	}
    
	void *PropertyInternal::getBackPointer()
	{
		return pBackPointer;
	}

	void PropertyInternal::createChangeItem(ChangeTypeFlags flags)
	{
		pParent->addChangeItemToGroup(this, flags);
		createChangeItemForShadowingProperties(flags);
	}

	void PropertyInternal::createChangeItemForShadowingProperties(ChangeTypeFlags flags)
	{
		for(vector<Property*>::iterator  it = shadowingProperties.begin(); it != shadowingProperties.end();  it++)
		{
			pParent->addChangeItemToGroup(*it, flags);
		}
	}

	void PropertyInternal::addShadow(Property *pProperty)
	{
		shadowingProperties.push_back(pProperty);
	}

}}
