using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Unity.Microsoft.Logging;

namespace GarmentFactoryContracts.DI
{
	public class UnityDependencyContainer : IDependencyContainer
	{
		private readonly UnityContainer _unityContainer;

		public UnityDependencyContainer()
		{
			_unityContainer = new UnityContainer();
		}

		public void AddLogging(Action<ILoggingBuilder> configure)
		{
			_unityContainer.AddExtension(new LoggingExtension(LoggerFactory.Create(configure)));
		}

		public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
		{
			if (isSingle)
			{
				_unityContainer.RegisterSingleton<T, U>();
			}
			else
			{
				_unityContainer.RegisterType<T, U>();
			}
		}

		public void RegisterType<T>(bool isSingle) where T : class
		{
			if (isSingle)
			{
				_unityContainer.RegisterSingleton<T>();
			}
			else
			{
				_unityContainer.RegisterType<T>();
			}
		}

		public T Resolve<T>()
		{
			return _unityContainer.Resolve<T>();
		}
	}
}
