using Integrations.Data;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace Monitoring.AppHost.DbContextFactories;

internal sealed class IntegrationsDbContextFactory : IDesignTimeDbContextFactory<DataContext>
{
	public DataContext CreateDbContext(string[] args)
	{
		var builder = DistributedApplication.CreateBuilder(args);

		var pg = builder.AddPostgres(Constants.DatabaseModuleName)
			.WithDataVolume(Constants.DatabaseVolumeName);
		var db = pg.AddDatabase(Constants.ForwarderDatabaseName);

		var options = new DbContextOptionsBuilder<DataContext>()
			.UseNpgsql(Constants.ForwarderDatabaseName) // ключ ресурса Aspire
			.Options;

		return new DataContext(options);
	}
}
