using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GreenTree.Nachtragsmanagement.Services.Configuration
{
    public static class ConfigurationHelper
    {
        /// <summary>
        /// Returns all available configuration references
        /// </summary>
        public static Dictionary<string, IConfigurationReference> GetAllConfigurationReferences()
        {
            var stateConfigurationReference = new StateConfigurationReference();

            return new Dictionary<string, IConfigurationReference>()
            {
                { stateConfigurationReference.Name, stateConfigurationReference }
            };
        }

        /// <summary>
        /// Returns all available configuration references for display
        /// </summary>
        public static Dictionary<string, string> GetAllConfigurationReferencesDisplayList()
        {
            var stateConfigurationReference = new StateConfigurationReference();

            return new Dictionary<string, string>()
            {
                { stateConfigurationReference.Name, stateConfigurationReference.DisplayName }
            };
        }

        /// <summary>
        /// Returns the configurationReference to the corresponding name
        /// </summary>
        /// <param name="name">Name of the configurationReference.</param>
        public static IConfigurationReference GetConfigurationReferenceByName(string name)
        {
            var allConfigurationReferences = GetAllConfigurationReferences();

            return
                allConfigurationReferences
                    .Any(c => c.Key == name)
                        ? allConfigurationReferences
                            .First(c => c.Key == name).Value
                        : null;
        }
    }
}