using NeonSprawl.Server.Game.PositionState;
using NeonSprawl.Server.Game.Skills;

namespace NeonSprawl.Server.Game.Mastery;

/// <summary>Registers perk state persistence and unlock engine (NEO-47).</summary>
public static class PerkStateServiceCollectionExtensions
{
    public static IServiceCollection AddPerkStateStore(this IServiceCollection services, IConfiguration configuration)
    {
        var cs = configuration.GetConnectionString(PositionStateServiceCollectionExtensions.NeonSprawlConnectionStringName);
        if (!string.IsNullOrWhiteSpace(cs))
        {
            services.AddSingleton<IPlayerPerkStateStore, PostgresPlayerPerkStateStore>();
        }
        else
        {
            services.AddSingleton<IPlayerPerkStateStore, InMemoryPlayerPerkStateStore>();
        }

        services.AddSingleton<PerkUnlockEngine>();
        return services;
    }
}
