namespace ReportingServices.Shared.HelperClasses;

public static class APIHelperFunctions
{
    public static string GetBeginningOfWeekAsAPIString()
    {
        DateTime date = DateTime.Now;

        int dayOfWeek = (int)date.DayOfWeek;

        date = dayOfWeek switch
        {
            0 => date.AddDays(-6),
            1 => date,
            _ => date.AddDays(1 - dayOfWeek)
        };

        return GetDateTimeAsAPIString(date.ToString(), false);
    }

    public static string GetDateWithOffsetAsAPIString(string dateString, float offset)
    {
        DateTime date = DateTime.Parse(dateString);

        date = date.AddHours(offset);

        return GetDateTimeAsAPIString(date.ToString(), true);
    }

    public static string GetDateTimeAsAPIString(string dateString, bool fullDateTime)
    {
        DateTime date = DateTime.Parse(dateString);

        if (fullDateTime)
            dateString = date.ToString("yyyy-M-d HH:mm:ss");
        else
            dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0";

        return dateString;
    }

    public static List<T> ReverseList<T>(List<T> inputList)
    {
        List<T> temp = new();

        for (int i = inputList.Count - 1; i >= 0; i--)
        {
            temp.Add(inputList[i]);
        }

        return temp;
    }
}