namespace MyOffice.Migrations.Sqlite;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using MyOffice.DbContext;
using MyOffice.Shared;

public class AppDbContextFactorySqlite : IDesignTimeDbContextFactory<AppDbContext>
{
	public AppDbContext CreateDbContext(string[]? args)
	{
		var builder = new DbContextOptionsBuilder<AppDbContext>();

		var sharedConfiguration = SharedConfiguration.CreateConfigurationContainer();
		var connectionString =
			args?.FirstOrDefault()
			?? sharedConfiguration.GetConnectionString("sqlite");

		builder.UseSqlite(connectionString, b => b.MigrationsAssembly("MyOffice.Migrations.Sqlite"));

		var db = new AppDbContext(AppDbContextProvidersEnum.sqlite, builder.Options);
		db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

		return db;
	}
}