using TravelCompanyBusinessLogic.BusinessLogic.OperatorLogics;
using TravelCompanyBusinessLogic.BusinessLogic.TouristLogics;
using TravelCompanyBusinessLogic.BusinessLogics;
using TravelCompanyBusinessLogic.OfficePackage.Implements;
using TravelCompanyBusinessLogic.OfficePackage;
using TravelCompanyClientApp;
using TravelCompanyContracts.BusinessLogicsContracts;
using TravelCompanyContracts.BusinessLogicsContracts.OperatorBusinessLogicsContracts;
using TravelCompanyContracts.BusinessLogicsContracts.TouristBusinessLogicsContracts;
using TravelCompanyContracts.StoragesContracts.OperatorStoragesContracts;
using TravelCompanyContracts.StoragesContracts.TouristStoragesContracts;
using TravelCompanyDatabaseImplement.Implements;
using TravelCompanyBusinessLogic.MailWorker;
using TravelCompanyContracts.BindingModels;
using TravelCompanyClientApp.Controllers;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddTransient<ITouristStorage, TouristStorage>();
builder.Services.AddTransient<ITravelStorage, TravelStorage>();
builder.Services.AddTransient<IExcursionStorage, ExcursionStorage>();
builder.Services.AddTransient<IPlaceStorage, PlaceStorage>();
builder.Services.AddTransient<ITourStorage, TourStorage>();
builder.Services.AddTransient<IGuideStorage, GuideStorage>();
builder.Services.AddTransient<IOperatorStorage, OperatorStorage>();

builder.Services.AddTransient<ITouristLogic, TouristLogic>();
builder.Services.AddTransient<IOperatorLogic, OperatorLogic>();
builder.Services.AddTransient<ITravelLogic, TravelLogic>();
builder.Services.AddTransient<IExcursionLogic, ExcursionLogic>();
builder.Services.AddTransient<IPlaceLogic, PlaceLogic>();
builder.Services.AddTransient<ITourLogic, TourLogic>();
builder.Services.AddTransient<IGuideLogic, GuideLogic>();
builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddSingleton<ILoadLogic, LoadLogic>();


builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();
var mailSender = app.Services.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
    MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
    MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
    SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
    SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
    PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
    PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
});
var loadLogic = app.Services.GetService<ILoadLogic>();
loadLogic?.LoadFromJson();
    // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Travel}/{action=Travel}/{id?}");

app.Run();