using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ZionRobot.Helpers
{
    class Shift
    {
        internal static bool isDateValid(string date, string culture = @"pt-BR",
            System.Globalization.DateTimeStyles timeStyle = System.Globalization.DateTimeStyles.None)
        {
            return DateTime.TryParse(
                date,
                new System.Globalization.CultureInfo(culture),
                timeStyle,
                out DateTime dateTime);
        }

        internal static bool isDuringTheWeek(DateTime date)
        {
            return date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday;
        }

        internal static bool isWeekend(DateTime date)
        {
            return !isDuringTheWeek(date);
        }

        internal static string formatDate(string date, string format = @"dd//MM/yyyy HH:mm:ss", string culture = @"pt-BR")
        {
            return DateTime.Parse(date,new System.Globalization.CultureInfo(culture)).ToString(format);
        }

        internal static List<DateTime> getDaysWithInterval(DateTime from, int interval = 30 , bool onlyBusiness = true)
        {
            List<DateTime> result = new List<DateTime>();

            DateTime endDate = from.AddDays(30);

            for(DateTime date = from; date <= endDate; date = date.AddDays(1))
            {
                if (onlyBusiness && isDuringTheWeek(date))
                {
                    result.Add(date);
                }

                if (!onlyBusiness)
                {
                    result.Add(date);
                }
            }

            return result;
        }

    }
}
