using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Shared
{
    public static class ExMethod
    {
        public static string ShamciToFormatShamciinFront(this string str)
        {
            if (string.IsNullOrEmpty(str)) return "";
            return str.Substring(0, 4) + "/" + str.Substring(4, 2) + "/" + str.Substring(6, 2);
        }
        public static string ConvertMiladiToShamsiinFront(this DateTime date)
        {
            PersianCalendar PersianCal = new PersianCalendar();
            return PersianCal.GetYear(date).ToString("0000") +
                   PersianCal.GetMonth(date).ToString("00") +
                   PersianCal.GetDayOfMonth(date).ToString("00")
                   ;
        }
        public static DateTime ToMiladiinFront(this string value)
        {
            PersianCalendar p = new PersianCalendar();
            return p.ToDateTime(Convert.ToInt32(value.Substring(0, 4)), Convert.ToInt32(value.Substring(4, 2)), Convert.ToInt32(value.Substring(6, 2)), DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
        }
        public static string GetEnumDisplayName(this Enum enumType)
        {
            return enumType.GetType().GetMember(enumType.ToString())
                   .First()
                   .GetCustomAttribute<DisplayAttribute>()
                    .Name;
        }
    }
}
