using Microsoft.EntityFrameworkCore;
using Npgsql;
using Register_office.Properties;

namespace Register_office.Properties
{
	internal class RegisterOfficeFactory
	{
		internal static bool CanConnect = false;
		internal static RegisterOfficeContext Create(string username, string password)
		{
			var builder = new NpgsqlConnectionStringBuilder()
			{
				Host = Settings.Default.Host,
				Database = Settings.Default.Database,
				Username = username,
				Password = password
			};

			var optionsBuilder = new DbContextOptionsBuilder<RegisterOfficeContext>();
			optionsBuilder.UseNpgsql(builder.ToString());

			RegisterOfficeContext dbContext = new(optionsBuilder.Options);
			CanConnect = dbContext.Database.CanConnect();

			return dbContext;
		}
	}
}
