using System;
using System.Collections;
using System.Collections.Generic;
using BeWo.Data.Entities;
using BeWo.Report.ReportObjects;
using BS.Shared.Core;


namespace BeWo.LeiendeckerReports
{
	public class LeiendeckerMitarbeiterstundenkontoBerechnung : MitarbeiterstundenkontoBerechnung
	{
		public override AbsenceTimeDays GetAbsenceTimeDays(IList<AbsenceTime> absenceTimes, DateTime start, DateTime end)
		{
			decimal? tage = null;
			if (absenceTimes != null)
			{
				foreach (var item in absenceTimes)
				{
					if (!String.IsNullOrEmpty(item.AbsenceReason.Description) &&
						(item.AbsenceReason.Description.ToLower().IndexOf("überstundenfrei") == -1))
					{

						var span = new DateTimeSpan();

						span.StartDate = start;

						if (item.Start.HasValue && item.Start.Value > span.StartDate)
						{
							span.StartDate = item.Start.Value;
						}
						span.EndDate = end;
						if (item.End.HasValue && item.End.Value.Date.AddDays(1) < span.EndDate)
						{
							span.EndDate = item.End.Value.Date.AddDays(1);
						}
						if (span.EndDate >= start && span.StartDate < end)
						{
							DateTime day = span.StartDate;
							while (day < end && day < span.EndDate)
							{
								if (!IstFeiertag(day) && day.DayOfWeek != DayOfWeek.Saturday && day.DayOfWeek != DayOfWeek.Sunday)
								{
									if (!tage.HasValue)
										tage = 0;

									tage += 24;
								}
								day = day.AddDays(1);
							}

						}
					}
				}
			}
			if (tage.HasValue)
				tage /= 24;

			var ath = new AbsenceTimeDays();
			ath.TageGesamt = tage;
			return ath;
		}

		public override bool IsServiceRecordFehlzeit(ServiceRecord sr)
		{
			return false;
		}

		public override bool AddServiceRecordToDuration(ServiceRecord sr)
		{
			if (sr.ServiceDescription != null && !String.IsNullOrEmpty(sr.ServiceDescription.Name) && sr.ServiceDescription.Name.ToLower().IndexOf("pause") >= 0)
				return false;
			return base.AddServiceRecordToDuration(sr);
		}

		public override decimal? GetFehlzeiten(IList<ServiceRecord> records, DateTime monat)
		{
			return 0;
		}

		//public override decimal? GetUrlaubKrankheit(IList<AbsenceTime> absenceTimes, DateTime monat)
		//{
		//	decimal? tage = null;
		//	if (absenceTimes != null)
		//	{
		//		foreach (var item in absenceTimes)
		//		{
		//			if (!String.IsNullOrEmpty(item.AbsenceReason.Description) &&
		//				(item.AbsenceReason.Description.ToLower().IndexOf("überstundenfrei") == -1))
		//			{


		//				DateTimeSpan span = new DateTimeSpan();

		//				span.StartDate = monat;

		//				if (item.Start.HasValue && item.Start.Value > span.StartDate)
		//				{
		//					span.StartDate = item.Start.Value;
		//				}
		//				span.EndDate = monat.AddMonths(1);
		//				if (item.End.HasValue && item.End.Value.Date.AddDays(1) < span.EndDate)
		//				{
		//					span.EndDate = item.End.Value.Date.AddDays(1);
		//				}
		//				if (span.EndDate >= monat && span.StartDate < monat.AddMonths(1))
		//				{
		//					DateTime day = span.StartDate;
		//					while (day < monat.AddMonths(1) && day < span.EndDate)
		//					{
		//						if (!IstFeiertag(day) && day.DayOfWeek != DayOfWeek.Saturday && day.DayOfWeek != DayOfWeek.Sunday)
		//						{
		//							if (!tage.HasValue)
		//								tage = 0;

		//							tage += 24;
		//						}
		//						day = day.AddDays(1);
		//					}

		//				}
		//			}
		//		}
		//	}
		//	if (tage.HasValue)
		//		tage /= 24;
		//	return tage;
		//}
	}
}
