
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using System.Web;
using System.Web.Configuration;
using System.Web.Mvc;

namespace CatalogSupport
{
    public class Utils
    {

        public static List<SelectListItem> GetEnumDescriptions<T>()
        {
            Type enumList = typeof(T);
            var list = System.Enum.GetValues(typeof(T));
            //var list = Enum.GetValues(typeof(T));
            List<SelectListItem> output = new List<SelectListItem>();
            foreach (var item in list)
            {
                FieldInfo fi = item.GetType().GetField(item.ToString());

                DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attributes != null && attributes.Length > 0 && attributes[0].Description != null)
                {
                    output.Add(new SelectListItem { Text = attributes[0].Description, Value = ((int)item).ToString() });

                }
                else
                {
                    output.Add(new SelectListItem { Text = item.ToString(), Value =  ((int)item).ToString() });
                }
            }
            return output;
        }

        
        

        public static void LogException(Exception ex, string userName, string userId, string data)
        {
            
            
            Trace.TraceError("Error For User= {0}, UserId= {1} ", userName, userId);
            Trace.TraceError("Error with Json{0}", data);
            Trace.TraceError("Error in * Message = {0}, * InnerException = {1}, * StackTrace = {2} ",
                ex.Message, ex.InnerException, ex.StackTrace);

        }
        
    }
}