using System.Net.Http;
using Knot.Contracts.Stories.Infrastructure.Persistence;
using Knot.Modules.Stories.Application.Abstractions;
using Knot.Modules.Stories.Infrastructure.Database;
using Knot.Modules.Stories.Infrastructure.Persistence.Mongo;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;

namespace Knot.Modules.Stories;

public static class DependencyInjection
{
    public static IServiceCollection AddStoriesModule(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddScoped<IStoryRepository, StoryRepository>();
        services.AddScoped<IUserRepository, UserRepository>();
        services.AddScoped<IStoryNotificationService, StoryNotificationService>();
        services.AddScoped<Knot.Contracts.Stories.Infrastructure.Persistence.IStoryCollection, StoryCollection>();

        var connectionString = configuration.GetConnectionString("DefaultConnection");
        services.AddDbContext<Infrastructure.Database.StoriesDbContext>(options =>
            options.UseNpgsql(connectionString));

        StoriesMongoMapConfigurator.Configure();

        services.AddMediatR(config =>
            config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));

        return services;
    }
}
