#pragma once

#include <sstream>
#include "Parameter.h"


class k_SliderParameter
	: public k_BaseParameter
	, public ISliderParameter
{
public:
	k_SliderParameter(IDirect3D9BasePlugin& ar_Plugin, const GUID& ar_Guid, const std::wstring& as_Name, const std::wstring& as_DisplayText, const std::wstring& as_Description, int ai_Min, int ai_Max, int ai_Default)
		: k_BaseParameter(ar_Plugin, ar_Guid, as_Name, as_DisplayText, as_Description, r_ParameterType::Slider)
		, mi_Max(ai_Max)
		, mi_Min(ai_Min)
		, mi_Default(ai_Default)
		, mi_Current(ai_Default)
	{
		this->UpdateDisplayText();
	}

	// IObject
	void* QueryInterface(const GUID& ar_InterfaceGuid)
	{
		if (ar_InterfaceGuid == __uuidof(ISliderParameter)) 
			return static_cast<ISliderParameter*>(this);

		return k_BaseParameter::QueryInterface(ar_InterfaceGuid); 
	}

	// ISliderParameter
	virtual void set_MaxValue(int ai_Value)
	{
		mi_Max = ai_Value;
	}

	virtual int get_MaxValue() const
	{
		return mi_Max;
	}
	
	virtual void set_MinValue(int ai_Value)
	{
		mi_Min = ai_Value;
	}

	virtual int get_MinValue() const
	{
		return mi_Min;
	}

	virtual void set_DefaultValue(int ai_Value)
	{
		mi_Default = ai_Value;
	}

	virtual int get_DefaultValue() const
	{
		return mi_Default;
	}

	virtual void set_CurrentValue(int ai_Value)
	{
		mi_Current = std::max<int>(std::min<int>(mi_Max, ai_Value), mi_Min);
		this->UpdateDisplayText();
		mr_Plugin.OnParameterHasChanged(*this);
	}

	virtual int get_CurrentValue() const
	{
		return mi_Current;
	}
	
	virtual void ResetToDefault()
	{
		mi_Current = mi_Default;
		this->UpdateDisplayText();
		mr_Plugin.OnParameterHasChanged(*this);
	}

	virtual std::wstring ToString()
	{
		std::wstringstream ls_Stream;
		ls_Stream << mi_Current;
		return ls_Stream.str();
	}

	virtual void FromString(const std::wstring& as_Value)
	{
		std::wstringstream ls_Stream(as_Value);
		ls_Stream >> mi_Current;
	}

protected:
	void UpdateDisplayText()
	{
		//std::wstringstream ls_Stream;
		//ls_Stream << mi_Current;
		//ms_DisplayText = ls_Stream.str();
	}

	int mi_Min;
	int mi_Max;
	int mi_Default;
	int mi_Current;
};
