using IWS5.DatabaseAccess.Interfaces;
using IWS5.DatabaseAccess.Interfaces.IAdmin;
using IWS5.DatabaseAccess.IwsDataContext;
using IWS5.DatabaseAccess.Repositories;
using IWS5.DatabaseAccess.Repositories.IAdmin;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace IWS5.DatabaseAccess.Extensions;

public static class ServiceCollectionExtensions
{
    public static void RegisterDatabaseAccess(this IServiceCollection services, IConfiguration configuration)
    {
        //Level of compatibility with SQL Server can get using query SELECT name, compatibility_level FROM sys.databases
        //It describes how current database is compatible with most recent entity framework
        services.AddDbContext<GreenfieldPd2015Context>(options => options
            .UseSqlServer(configuration
                .GetConnectionString(GreenfieldPd2015Context.ConnectionStringName), o => o.UseCompatibilityLevel(100)));

        services.AddScoped<IRightsRepository, RightsRepository>();
        services.AddScoped<IProcessRepository, ProcessRepository>();
        services.AddScoped<IDocumentRepository, DocumentRepository>();
        services.AddScoped<INoteRepository, NoteRepository>();
        services.AddScoped<IQueueRepository, QueueRepository>();
        services.AddScoped<IWorkItemReferenceRepository, WorkItemReferenceRepository>();
        services.AddScoped<IButtonRepository, ButtonRepository>();
        services.AddScoped<IFieldDefinitionRepository, FieldDefinitionRepository>();
        services.AddScoped<IDocumentCabinetRepository, DocumentCabinetRepository>();
        services.AddScoped<IDocumentCabinetDefinitionRepository, DocumentCabinetDefinitionRepository>();
        services.AddScoped<IConnectionRepository, ConnectionRepository>();
        services.AddScoped<ITrackingRecordRepository, TrackingRecordRepository>();
        services.AddScoped<IFieldInstanceDateRepository, FieldInstanceDateRepository>();
        services.AddScoped<IFieldInstanceNumberRepository, FieldInstanceNumberRepository>();
        services.AddScoped<IFieldInstanceStringRepository, FieldInstanceStringRepository>();
        services.AddScoped<IFieldInstanceOptionRepository, FieldInstanceOptionRepository>();
        services.AddScoped<IProcessDocumentTemplateRightsRepository, ProcessDocumentTemplateRightsRepository>();
        services.AddScoped<IUserRepository, UserRepository>();
        services.AddScoped<IUserPropertyRepository, UserPropertyRepository>();
        services.AddScoped<IEventDefinitionRepository, EventDefinitionRepository>();
        services.AddScoped<IEventTypeRepository, EventTypeRepository>();
        services.AddScoped<IInboxEventRepository, InboxEventRepository>();
        services.AddScoped<ITriggerDefinitionRepository, TriggerDefinitionRepository>();
        services.AddScoped<ICustomQueryRepository,  CustomQueryRepository>();
        services.AddScoped<IPendingWorkItemReferenceRepository, PendingWorkItemReferenceRepository>();
        services.AddScoped<ITimerRepository, TimerRepository>();
        services.AddScoped<IExceptionNoteRepository, ExceptionNoteRepository>();
        services.AddScoped<ISystemParameterRepository, SystemParameterRepository>();
        services.AddScoped<IMailRepository, MailRepository>();
        services.AddScoped<IReportRepository, ReportRepository>();
        services.AddScoped<IScheduleRepository, ScheduleRepository>();
        services.AddScoped<IScheduleTaskRepository, ScheduleTaskRepository>();
        services.AddScoped<IServerRepository, ServerRepository>();
    }
}
