

#pragma once

#include <map>
#include "IProperty.h"

namespace mdd
{

	template<typename TYPE>
	class Property : public IProperty
	{
		PropertyValue<TYPE> val;
		std::map<std::string, std::shared_ptr<IProperty>> _subprops;
	protected:
		virtual IPropertyValue* GetPropertyValue()
		{
			return &val;
		}

	public:
		typedef std::shared_ptr<Property<TYPE>> Ptr;

		virtual std::shared_ptr<IProperty> GetSubProp(const std::string& name)
		{
			auto sub = _subprops.find(name);
			if (sub == _subprops.end())
			{
				return std::make_shared<Property<bool>>();
			}
			else
			{
				return sub->second;
			}
		}

		template<typename T>
		std::shared_ptr<Property<T>> addSubProperty(const std::string& name)
		{
			auto newprop = std::make_shared<Property<T>>();
			_subprops[name] = newprop;
			return newprop;
		}

		template<typename T>
		std::shared_ptr<Property<T>> addSubProperty(const std::string& name, const T& default_val)
		{
			auto newprop = std::make_shared<Property<T>>();
			newprop->Value() = default_val;
			_subprops[name] = newprop;
			return newprop;
		}

		TYPE& Value()
		{
			return *val.value;
		}
	};

}