using MEU.API.Config;
//using MEU.API.Models;
using Sieve.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

namespace MEU.API.Utils
{

    
    public class CommonUtils
    {
        public static DateTime ConvertToClientStartDate(DateTime dtInput) {
            if (dtInput.Hour > 12)
            {
                return dtInput.AddHours(24 - dtInput.Hour);
            }
            else
            {
                return dtInput.AddHours(-dtInput.Hour);
            }
        }
        private static readonly string[] VietnameseSigns = new string[]
        {

            "aAeEoOuUiIdDyY",

            "áàạảãâấầậẩẫăắằặẳẵ",

            "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",

            "éèẹẻẽêếềệểễ",

            "ÉÈẸẺẼÊẾỀỆỂỄ",

            "óòọỏõôốồộổỗơớờợởỡ",

            "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",

            "úùụủũưứừựửữ",

            "ÚÙỤỦŨƯỨỪỰỬỮ",

            "íìịỉĩ",

            "ÍÌỊỈĨ",

            "đ",

            "Đ",

            "ýỳỵỷỹ",

            "ÝỲỴỶỸ"
        };

        //public static string getFullName(user usr)
        //{
        //    if (usr==null)
        //    {
        //        return "";
        //    }
        //    return (usr?.first_name?.Trim() + " " + usr?.middle_name?.Trim() + " " + usr?.last_name?.Trim()).Replace("  ", " ");
        //}
        public static string RemoveSignAndLowerCase4VietnameseString(string str)
        {
            str = str.ToLower();
            for (int i = 1; i < VietnameseSigns.Length; i++)
            {
                for (int j = 0; j < VietnameseSigns[i].Length; j++)
                    str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
            }
            return str;
        }
        public static DateTime FirstDateOfWeekISO8601(int year, int weekOfYear)
        {
            DateTime jan1 = new DateTime(year, 1, 1);
            int daysOffset = DayOfWeek.Thursday - jan1.DayOfWeek;

            // Use first Thursday in January to get first week of the year as
            // it will never be in Week 52/53
            DateTime firstThursday = jan1.AddDays(daysOffset);
            var cal = CultureInfo.CurrentCulture.Calendar;
            int firstWeek = cal.GetWeekOfYear(firstThursday, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

            var weekNum = weekOfYear;
            // As we're adding days to a date in Week 1,
            // we need to subtract 1 in order to get the right date for week #1
            if (firstWeek == 1)
            {
                weekNum -= 1;
            }

            // Using the first Thursday as starting week ensures that we are starting in the right year
            // then we add number of weeks multiplied with days
            var result = firstThursday.AddDays(weekNum * 7);

            // Subtract 3 days from Thursday to get Monday, which is the first weekday in ISO8601
            return result.AddDays(-3);
        }
        public static int? getTakeNumber(SieveModel sieveModel)
        {
            int? take = null;

            if (string.IsNullOrEmpty(sieveModel.Filters) && string.IsNullOrEmpty(sieveModel.Sorts))
            {
                if (sieveModel.PageSize == null)
                    take = ConfigEnvironment.DEFAULT_PAGE_SIZE;
                else
                    take = sieveModel.PageSize.Value;
            }

            return take;

        }
    }
}
