using Hotline.Configurations;
using Microsoft.Extensions.DependencyInjection;
using XF.Domain.Authentications;
using XF.Domain.Dependency;

namespace Hotline.Authentications;

public class SessionContextProvider : ISessionContextProvider, IScopeDependency
{
    private readonly IServiceProvider _serviceProvider;
    public ISessionContext SessionContext { get; set; }

    public SessionContextProvider(IServiceProvider serviceProvider, ISessionContext sessionContext)
    {
        _serviceProvider = serviceProvider;
        SessionContext = sessionContext;
    }

    public void SetContext(string key)
    {
        SessionContext = _serviceProvider.GetRequiredKeyedService<ISessionContext>(key);
    }

    public void SetContext(ISessionContext sessionContext)
    {
        SessionContext = sessionContext;
    }
}