using System;
using System.Collections.Generic;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Invoicing;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Services;

namespace LebenshilfeCoburg.Invoicing
{
	public class LhCoburgInvoiceFactory : InvoiceFactory
	{
		


		public override InvoiceCreation CreateInvoiceCreator(string specificId, string tenant, Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
		{
			
			foreach (var item in supportConcepts2ServiceRecords)
			{
				var csc = item.Key;
				var cb2sc = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(csc.CostBearerRelOids[0]);
				
				foreach (var scap in cb2sc.ApprovalPeriodList)
				{
					if (scap.ServiceCategory != null)
					{
						var sd = scap.ServiceCategory;
						String name = "";
						if (!String.IsNullOrEmpty(sd.Name))
						{
							name = sd.Name.ToLower().Trim();
						}
						if (name == "auw pers. budget")
						{
							return new LhCoburgPBInvoiceCreation();
						}
						if (name == "schulassistenz" || name == "arbeitsassistenz")
						{
							return new LhCoburgAusbildungsassistenzInvoiceCreation();
						}
					}
				}
			}
			return new LhCoburgAssistenzInvoiceCreation();
			
		}
		
	}
}
