using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TodoList.Application.Data;
using TodoList.Application.Interfaces;
using TodoList.Application.Repositories;
using TodoList.Application.Services;
using TodoList.Core.Interfaces;
using ITaskService = TodoList.Application.Interfaces.ITaskService;

namespace TodoList.Application;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddApplicationServices(this IServiceCollection services, string connectionString)
    {
        services.AddDbContext<TodoDbContext>(options => 
            options.UseSqlite(connectionString, b => b.MigrationsAssembly("TodoList.Application")));
        services.AddScoped<ITaskRepository, TaskRepository>();
        services.AddScoped<ITaskService, TaskService>();

        return services;
    }
}
