using NUnit.Framework;
using System;
using Library;

namespace TestLibrary
{
    [TestFixture]
    public class CalculationsTests
    {
        [Test]
        public void AvailablePeriods_NotEnoughTimeAtStart_ShouldSkipShortPeriod()
        {
            var calculator = new Calculations();
            var startTimes = new TimeSpan[] { new TimeSpan(9, 0, 0) };
            var durations = new int[] { 45 };
            var beginWorkingTime = new TimeSpan(9, 0, 0);
            var endWorkingTime = new TimeSpan(12, 0, 0);
            var consultationTime = 30;
            
            var result = calculator.AvailablePeriods(
                startTimes,
                durations,
                beginWorkingTime,
                endWorkingTime,
                consultationTime);
            
            var expected = new string[] { "09:45-10:15", "10:15-10:45", "10:45-11:15", "11:15-11:45" };
            
            Assert.That(expected, Is.EqualTo(result));
        }

        [Test]
        public void AvailablePeriods_VariousDurationsAndBusyEnd_ShouldReturnCorrectPeriods()
        {
            var calculator = new Calculations();
            var startTimes = new TimeSpan[] 
            { 
                new TimeSpan(10, 0, 0), 
                new TimeSpan(11, 30, 0),
                new TimeSpan(15, 45, 0)
            };
            var durations = new int[] { 30, 90, 75 };
            var beginWorkingTime = new TimeSpan(9, 0, 0);
            var endWorkingTime = new TimeSpan(17, 0, 0);
            var consultationTime = 30;
            
            var result = calculator.AvailablePeriods(
                startTimes,
                durations,
                beginWorkingTime,
                endWorkingTime,
                consultationTime);
            
            var expected = new string[]
            {
                "09:00-09:30",
                "09:30-10:00",
                "10:30-11:00",
                "11:00-11:30",
                "13:00-13:30",
                "13:30-14:00",
                "14:00-14:30",
                "14:30-15:00",
                "15:00-15:30"
            };
            
            Assert.That(expected, Is.EqualTo(result));
        }
    }
}