﻿using Albatross.DbScripting.Core;
using Albatross.DbScripting.SqlServer;
using SimpleInjector;
using SimpleInjector.Packaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Albatross.DbScripting.Ioc{
	public class SqlServerPackage : IPackage {
		public void RegisterServices(Container container) {
			var types = from type in typeof(TableInsert).Assembly.GetTypes()
						where typeof(ITableBasedQuery).IsAssignableFrom(type) && type != typeof(CompositeTableQuery)
						select type;
			var registrations = from type in types select Lifestyle.Singleton.CreateRegistration(type, container);
			container.RegisterCollection<ITableBasedQuery>(registrations);

			container.Register<ITableQueryFactory, TableQueryFactory>(Lifestyle.Singleton);
			container.Register<IGetVariableName, GetSqlVariableName>(Lifestyle.Singleton);
			container.Register<IGetTableColumns, GetTableColumns>(Lifestyle.Singleton);
			container.Register<IGetTableIdentityColumn, GetTableIdentityColumn>(Lifestyle.Singleton);
			container.Register<IGetTablePrimaryKey, GetTablePrimaryKey>(Lifestyle.Singleton);
			container.Register<ISetDbConnection, DbConnectionSetup>(Lifestyle.Singleton);
			container.Register<IGetDbConnectionString, DbConnectionSetup>(Lifestyle.Singleton);
			container.Register<IDeclareStatement, BuildDeclareStatement>(Lifestyle.Singleton);
			container.Register<IColumnSqlTypeBuilder, ColumnSqlTypeBuilder>(Lifestyle.Singleton);
			container.RegisterCollection<BuiltInColumn>(BuiltInColumns.Items);
			container.Register<IBuiltInColumnFactory, BuiltInColumnFactory>(Lifestyle.Singleton);
		}
	}
}
