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.DataContracts.Compact;
using DevExpress.Utils;

namespace BeWo.GpzBiberachReports.Invoicing
{
	public class GpzBiberachInvoiceFactory : 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 == "abw")
						{
							return new GpzBiberachAbwInvoiceCreation();
						}
						if (name == "abw +")
						{
							return new GpzBiberachAbwInvoiceCreation();
						}
						if (name == "persönliches budget")
						{
							return new GpzBiberachPBInvoiceCreation();
						}
						if (name == "soziotherapie")
						{
							return new SoziotherapieInvoiceCreation();
						}
						
						if (name == "pflegeergänzungsleistungen")
						{
							return new PflegeInvoiceCreation();
						}
						if (name == "miete")
						{
							return new MieteInvoiceCreation();
						}
						if (name == "sozialpsychiatrischer dienst")
						{

						}
						
							
						else if (!String.IsNullOrEmpty(sd.Name) && sd.Name.ToLower() == "arbeit")
						{
							return new GpzBiberachWfbInvoiceCreation();
						}
					}
				}
			}
			return new GpzBiberachDefaultInvoiceCreation();
			
		}

	}
}
