using Blazored.LocalStorage;
using Blazored.SessionStorage;
using Insight.Web.Services;
using Microsoft.AspNetCore.Components.Server.Circuits;
using MudBlazor.Services;

namespace Insight.Web.Hosting;

public static class ServiceExtensions
{
    internal static IServiceCollection AddWebServices(this IServiceCollection services)
    {
        // HOSTS
        services.AddHostedService<ServiceHost>();

        // LOCAL STORAGE
        services.AddBlazoredLocalStorage();
        services.AddBlazoredSessionStorage();

        // BLAZOR
        services.AddHttpContextAccessor();
        services.AddRazorPages();
        services.AddServerSideBlazor(options =>
        {
            options.DetailedErrors = true;
        });

        // CIRCUIT
        services.AddScoped<CircuitHandler>(p => p.GetRequiredService<SessionHandler>());
        services.AddScoped<SessionHandler>();
        services.AddSingleton<SessionPool>();

        // CHAT
        services.AddSingleton<ChatService>();

        // MUDBLAZOR
        services.AddMudServices(options =>
        {
            options.SnackbarConfiguration.PositionClass = MudBlazor.Defaults.Classes.Position.BottomLeft;
        });
        services.AddMudBlazorDialog();

        return services;
    }
}