using System;
using System.Collections.Generic;
using BeWo.Service.Invoicing;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;

namespace LebenshilfeCoburg.Calculation
{
	public class LhCoburgCalculations : BS.Shared.Services.Calculations
	{
		public override decimal? GetApprovedFixedAmountForPeriod(SupportConceptApprovalPeriodDC scap, DateTime? pStart, DateTime? pEnd,
			out decimal amountPerUnit, out decimal unitCount)
		{
			var amount = base.GetApprovedFixedAmountForPeriod(scap, pStart, pEnd, out amountPerUnit, out unitCount);


			if (scap.ApprovedFixedAmount.HasValue && scap.ApprovedFixedAmountInterval.HasValue && scap.ApprovedFixedAmountInterval.Value == SupportConceptApprovalInterval.Monthly)
			{
				DateTimeUnit du = pStart.Value.Date.GetDateTimeUnit(pEnd.Value.Date, TimeUnit.Month);
				amount = scap.ApprovedFixedAmount.Value * du.UnitCount;

				amountPerUnit = scap.ApprovedFixedAmount.Value;
				unitCount = du.UnitCount;

				//Die Berechnung bei Menschen, die währen des Monats mit der Betreuung Starten, bzw. die Betreuung endet.
				//Monatsbretag * 12 / 365 * Tage der Bewilligung (z.B. Start am 25.1.16 =7 Tage)
				//657,45 *12 / 365 * 7  = 151.30?

				if (du.RestDays > 0)
				{
					amount = amountPerUnit*12/365*du.RestDays;
					
				}

			}

			
			return amount;
		}
	}
}
