using System;

namespace mgaia.Utils.Persistence
{
	/// <summary>
	/// Interface de persistência padrão
	/// </summary>
	/// <owner>Victor</owner>
	public class DefaultPersistenceManagerPostProcessor : IPersistenceManagerPostProcessor
	{
		public object ProcessFromInterface(string key, object defaultValue, Type typeOfValue, IPersistenceFileInterface persistenceFileInterface)
		{
			object returnValue = default(object);

			if (typeOfValue.Equals(typeof(float)))
			{
				returnValue = persistenceFileInterface.GetFloat(key, (float)defaultValue);
			}
			else if (typeOfValue.Equals(typeof(int)))
			{
				returnValue = persistenceFileInterface.GetInt32(key, (int)defaultValue);
			}
			else if (typeOfValue.Equals(typeof(string)))
			{
				returnValue = persistenceFileInterface.GetString(key, (string)defaultValue);
			}
			else
			{
				Assert.AssertTrue(false, "Tipo desconhecido! Tipo : " + typeOfValue.Name);
			}

			return returnValue;
		}

		public void SaveToInterface(string key, object value, Type typeOfValue, IPersistenceFileInterface persistenceFileInterface)
		{
			if (typeOfValue.Equals(typeof(float)))
			{
				persistenceFileInterface.SetFloat(key, (float)value);
			}
			else if (typeOfValue.Equals(typeof(int)))
			{
				persistenceFileInterface.SetInt32(key, (int)value);
			}
			else if (typeOfValue.Equals(typeof(string)))
			{
				persistenceFileInterface.SetString(key, (string)value);
			}
			else
			{
				Assert.AssertTrue(false, "Tipo desconhecido! Tipo : " + typeOfValue.Name);
			}
		}
	}
}