using Microsoft.Extensions.DependencyInjection;
using NewsBlogAbstractions.WorkAbstractions;
using NewsBlogDatabaseImplementation.WorkImplementation;
using NewsBlogMongoDB.StoragesContracts;
using NewsBlogMongoDB;

namespace NewsBlogView
{
	internal static class Program
	{
		private static ServiceProvider? _serviceProvider;
		public static ServiceProvider? ServiceProvider => _serviceProvider;

		public static bool isPostgreSQL = true;

		/// <summary>
		///  The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			// To customize application configuration such as set high DPI settings or default font,
			// see https://aka.ms/applicationconfiguration.
			ApplicationConfiguration.Initialize();
			var services = new ServiceCollection();
			ConfigureServices(services);
			_serviceProvider = services.BuildServiceProvider();
			Application.Run(_serviceProvider.GetRequiredService<FormMain>());
		}

		private static void ConfigureServices(ServiceCollection services)
		{
			services.AddTransient<IArticleWork, ArticleWork>();
			services.AddTransient<IAuthorWork, AuthorWork>();
			services.AddTransient<ICategoryWork, CategoryWork>();
			services.AddTransient<ICommentWork, CommentWork>();
			services.AddTransient<ITagWork, TagWork>();

			services.AddTransient<StorageModel, ImplementationMongoDB>();

			services.AddTransient<FormMain>();
			services.AddTransient<FormArticle>();
			services.AddTransient<FormAuthor>();
			services.AddTransient<FormCategory>();
			services.AddTransient<FormComment>();
			services.AddTransient<FormTag>();
		}
	}
}