using ReportingServices.Shared.HelperClasses;

namespace ReportingServices.Test
{
    [TestClass]
    public class APIHelperTester
    {
        [TestMethod]
        public void CheckShortDateWithPassedInDate()
        {
            // Arrange
            string date = DateTime.Now.ToString("yyyy-M-d") + " 0:0:0";

            // Act
            string callerDate = APIHelperFunctions.GetDateTimeAsAPIString(DateTime.Now.ToString(), false);

            // Assert
            Assert.AreEqual(date, callerDate);
        }

        [TestMethod]
        public void CheckFullDateWithPassedInDate()
        {
            // Arrange
            string date = DateTime.Now.ToString("yyyy-M-d HH:mm:ss");

            // Act
            string callerDate = APIHelperFunctions.GetDateTimeAsAPIString(DateTime.Now.ToString(), true);

            // Assert
            Assert.AreEqual(date, callerDate);
        }

        [TestMethod]
        public void CheckStartDateForWeekNow()
        {
            // Arrange
            string date = DetermineDate();

            // Act
            string callerDate = APIHelperFunctions.GetBeginningOfWeekAsAPIString();

            // Assert
            Assert.AreEqual(date, callerDate);
        }

        [TestMethod]
        public void CheckStartDateForDayPassedInAndHoursAdded()
        {
            // Arrange
            string date = "2022-11-23 00:00:00";

            // Act
            string callerDate = APIHelperFunctions.GetDateWithOffsetAsAPIString("11/23/2022 12:30 PM", -12.5f);

            // Assert
            Assert.AreEqual(date, callerDate);
        }

        private string DetermineDate()
        {
            DateTime date = DateTime.Now;

            if (date.DayOfWeek == DayOfWeek.Monday)
                date = date.AddDays(-7);

            if (date.DayOfWeek == DayOfWeek.Tuesday)
                date = date.AddDays(-1);

            if (date.DayOfWeek == DayOfWeek.Wednesday)
                date = date.AddDays(-2);

            if (date.DayOfWeek == DayOfWeek.Thursday)
                date = date.AddDays(-3);

            if (date.DayOfWeek == DayOfWeek.Friday)
                date = date.AddDays(-4);

            if (date.DayOfWeek == DayOfWeek.Saturday)
                date = date.AddDays(-5);

            if (date.DayOfWeek == DayOfWeek.Sunday)
                date = date.AddDays(-6);

            return date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0"; ;
        }
    }
}