using KiMailOrderAgent;
using KiMailOrderAgent.Agents;
using KiMailOrderAgent.Approval;
using KiMailOrderAgent.Attachments;
using KiMailOrderAgent.Catalog;
using KiMailOrderAgent.Mail;
using KiMailOrderAgent.Services;
using KiMailOrderAgent.Settings;
using KiMailOrderAgent.Wawi;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;


var builder = Host.CreateApplicationBuilder(args);

builder.Services.Configure<ApprovalSettings>(
    builder.Configuration.GetSection("Approval"));

builder.Services.Configure<MailSettings>(
builder.Configuration.GetSection("Mail"));
builder.Services.Configure<MailFilterSettings>(
builder.Configuration.GetSection("MailFilter"));

builder.Services.AddSingleton<ApprovalMessageBuilder>();
builder.Services.AddSingleton<IApprovalNotifier, EmailApprovalNotifier>();
builder.Services.AddSingleton<IMailReader, ImapMailReader>();
builder.Services.AddSingleton<IWawiOrderService, WawiOrderService>();
builder.Services.Configure<AgentSettings>(
builder.Configuration.GetSection("Agent"));

builder.Services.Configure<AppModeSettings>(
    builder.Configuration.GetSection("AppMode"));

builder.Services.AddHttpClient<OrderAgent>();
builder.Services.AddHttpClient<CorrectionAgent>();
builder.Services.AddSingleton<CorrectionAgent>();
builder.Services.AddSingleton<OrderAgent>();

var agentSettings = builder.Configuration
    .GetSection("Agent")
    .Get<AgentSettings>();

builder.Services.AddSingleton<IArticleCatalogService, JsonArticleCatalogService>();
builder.Services.AddSingleton<OrderValidator>();
builder.Services.AddSingleton<OrderAgent>();
builder.Services.AddSingleton<IAttachmentTextExtractor, AttachmentTextExtractor>();
builder.Services.AddHostedService<Worker>();
builder.Services.AddSingleton<MailPreFilter>();
builder.Services.AddScoped<WawiDbService>();
builder.Services.AddHttpClient<WawiRegistrationService>();

var host = builder.Build();
host.Run();