#include "SIUnitInternal.h"
#include "SIPropertyInternal.h"

namespace NDTS
{
	namespace SCO
	{
	SIPropertyInternal::SIPropertyInternal(char *pShortName, char *pLongName, int flags, SI::BaseUnit baseUnit, SI::Prefix prefix) : PropertyInternal(pShortName, pLongName, flags)
	{
		pSIUnitInternal = new SIUnitInternal(baseUnit, prefix);
	}

	SIPropertyInternal::~SIPropertyInternal(void)
	{
		delete pSIUnitInternal;
	}

	double SIPropertyInternal::getValue()
	{
		return pSIUnitInternal->baseToPrefix(getSIValue());
	}

	void SIPropertyInternal::setValue(double value)
	{
		setSIValue(pSIUnitInternal->prefixToBase(value));
	}
	double SIPropertyInternal::getMin()
	{
		// If our unit is inverse, the min and max are the other way round to the 
		// base integerunit.  I.e. min Rep Rate in samples is the max frequency in Hz, Hz is an inverse unit
		if (!pSIUnitInternal->getIsInverse())
			return pSIUnitInternal->baseToPrefix(getSIMin());
		else
			return pSIUnitInternal->baseToPrefix(getSIMax());
	}
	double SIPropertyInternal::getMax()
	{
		if (!pSIUnitInternal->getIsInverse())
			return pSIUnitInternal->baseToPrefix(getSIMax());
		else
			return pSIUnitInternal->baseToPrefix(getSIMin());
	}

	SIUnit *SIPropertyInternal::getSIUnit()
	{
		return dynamic_cast<SIUnit*>(pSIUnitInternal);
	}

	void SIPropertyInternal::setBaseUnitOnly()
	{
		SI::BaseUnit base = pSIUnitInternal->getBaseUnit();
		delete pSIUnitInternal;
		pSIUnitInternal = new SIUnitInternal(base, SI::NoPrefix);
	}
}};