using System;
using Microsoft.Extensions.DependencyInjection;
using Sockeye.Models;

namespace Sockeye.Util
{
    /// <summary>
    /// Shared service provider for static classes    
    /// </summary>
    internal static class ServiceProviderProvider
    {
        private static IServiceProvider _provider;
        internal static IServiceProvider Provider
        {
            get { return _provider; }
            set { _provider = value; }
        }

        internal static IServiceScope Scope
        {
            get
            {
                return Provider.CreateScope();
            }
        }

        internal static AyContext DBContext
        {
            get
            {
                return Scope.ServiceProvider.GetRequiredService<AyContext>();
            }
        }

        internal static Sockeye.Api.ControllerHelpers.ApiServerState ServerState
        {
            get
            {
                return Scope.ServiceProvider.GetRequiredService<Sockeye.Api.ControllerHelpers.ApiServerState>();
            }
        }

        internal static Sockeye.Util.IMailer Mailer
        {
            get
            {
                return Scope.ServiceProvider.GetRequiredService<Sockeye.Util.IMailer>();
            }
        }

        // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1
        internal static System.Net.Http.IHttpClientFactory HttpClientFactory
        {
            get
            {
                return Scope.ServiceProvider.GetRequiredService<System.Net.Http.IHttpClientFactory>();
            }
        }


    }
}