using System;
using System.Collections.Generic;
using System.Text;
using Howest.SchemaDiscovery.DbObjects;
using Howest.Guidance.DataAccess.CodeGeneration.ObjectModel.NamingConventions;

namespace Howest.Guidance.DataAccess.CodeGeneration.ObjectModel.Helpers
{
	public static class DataAccessorHelper
	{
		public static Property GetPropertyByName(Entity entity, string propertyName)
		{
			return entity.Properties.Find(delegate(Property prop) {
				return prop.Name == propertyName;
			});
		}

		public static string GetMethodParameterList(SqlStatement statement)
		{
			string parList = "";
			bool isFirst = true;
			foreach (Parameter par in statement.Parameters)
			{
				if (isFirst)
					isFirst = false;
				else
					parList += ", ";
				parList += string.Format("{0} {1}", par.DbDataType.Type.ToString(), NamingHelper.GetVariableName(par.Name));
			}
			return parList;
		}

		public static string CreateParameterValues(Parameter par)
		{
			
			return string.Format("\"{0}\", {1}", par.DBName, NamingHelper.GetVariableName(par.Name));
		}

		public static string CreateParameterValues(Entity entity, string propertyName, Parameter par)
		{
			return string.Format("\"{0}\", {1}.{2}", par.DBName, NamingHelper.GetVariableName(entity.Name), propertyName);
		}
	}
}
