

#pragma once

#include <memory>
#include <string>

namespace mdd
{
	class IPropertyValue
	{
	public:
		virtual ~IPropertyValue(){}
		virtual std::string GetPropertyType() = 0;
	};

	template<typename TYPE>
	class PropertyValue : public IPropertyValue
	{
	public:
		std::string GetPropertyType()
		{
			return typeid(TYPE).name();
		}

		std::shared_ptr<TYPE> value = std::make_shared<TYPE>();
	};

	class IProperty
	{
	protected:
		virtual IPropertyValue* GetPropertyValue() = 0;

	public:

		virtual ~IProperty(){}

		virtual std::shared_ptr<IProperty> GetSubProp(const std::string& name) = 0;


		template<typename EXPECTED_TYPE>
		std::shared_ptr<EXPECTED_TYPE> Value()
		{
			if (GetPropertyValue()->GetPropertyType() != typeid(EXPECTED_TYPE).name())
			{
				return std::make_shared<EXPECTED_TYPE>();
			}
			else
			{
				return dynamic_cast<PropertyValue<EXPECTED_TYPE>>(GetPropertyValue())->value;
			}
		}
	};

}