using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Invoicing;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using BS.Shared.Services;

namespace BeWo.GpzBiberachReports.Invoicing
{
	[IDSpecificClass(Identifiers = new string[] { "Pflege" })]
	public class PflegeInvoiceCreation : InvoiceCreation
    {
		
		public override void SetInvoiceId(ServiceInvoice invoice)
		{
			invoice.InvoiceBase.InvoiceId = "Pflege";
			invoice.InvoiceBase.InvoiceTypeText = "Pflegeergänzungsleistungen";
		}

		public override void SetServiceInvoicePeriods(ServiceInvoice invoice, CostBearer2SupportConcept c2s, DateTimeSpan invoicePeriod, List<ServiceRecordDC> serviceRecords)
		{
			
			base.SetServiceInvoicePeriods(invoice, c2s, invoicePeriod, serviceRecords);
		}

		public override IList<InvoiceItem> CreateInvoiceItems(List<ServiceRecordDC> serviceRecordsInPeriod, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap, Calculations calc)
		{
			var list = base.CreateInvoiceItems(serviceRecordsInPeriod, invoicePeriod, scap, calc);

			return list;
		}

		public override IList<InvoiceItem> CreateSummaryInvoiceItems(IList<InvoiceItem> itemList, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap,
			Calculations calc)
		{
			return itemList;
		}

		public override InvoiceItem CreateInvoiceItem(ServiceRecordDC iServiceRecord, SupportConceptApprovalPeriod scap, Calculations calc)
		{
			var invoiceItem = new InvoiceItem();

			var bd = calc.GetBillingData(iServiceRecord);
			
			invoiceItem.AmountPerUnit = bd.AmountPerUnit;
			invoiceItem.UnitCount = bd.UnitCount;
			invoiceItem.AmountTotal = bd.AmountTotal;
			invoiceItem.ItemPeriodStart = bd.BillingPeriodStart;
			invoiceItem.ItemPeriodEnd = bd.BillingPeriodEnd;
			invoiceItem.RateFactor = bd.RateFactor;
			invoiceItem.GrossAmountTotal = bd.GrossAmountTotal;
			invoiceItem.AccountingInterval = bd.AccountingInterval;
			invoiceItem.ItemDescription = iServiceRecord.ServiceDescription.Name; //iServiceRecord.Employee + " - " + iServiceRecord.ServiceDescription.Name;
			invoiceItem.ServiceRecord = DAOFactory.GenericDAO.LoadByID<ServiceRecord>(iServiceRecord.ServiceRecordOid.Value);
			if (scap != null)
				invoiceItem.SupportConceptApprovalPeriodOid = scap.Oid;
			
			return invoiceItem;
		}

    }
}
