using NeonSprawl.Server.Game.PositionState;

namespace NeonSprawl.Server.Game.Gathering;

/// <summary>Registers resource-node instance persistence: PostgreSQL when configured, otherwise in-memory (NEO-61).</summary>
public static class ResourceNodeInstanceServiceCollectionExtensions
{
    public static IServiceCollection AddResourceNodeInstanceStore(this IServiceCollection services, IConfiguration configuration)
    {
        var cs = configuration.GetConnectionString(PositionStateServiceCollectionExtensions.NeonSprawlConnectionStringName);
        if (!string.IsNullOrWhiteSpace(cs))
        {
            services.AddSingleton<IResourceNodeInstanceStore, PostgresResourceNodeInstanceStore>();
        }
        else
        {
            services.AddSingleton<IResourceNodeInstanceStore, InMemoryResourceNodeInstanceStore>();
        }

        return services;
    }
}
