using Microsoft.Extensions.Logging;
using TIAMMobileApp.Services;
using TIAMWebApp.Shared.Application.Interfaces;
using DevExpress.Blazor;
using System.Resources;
using AyCode.Interfaces.StorageHandlers;
using TIAMWebApp.Shared.Application.Utility;
using TIAMWebApp.Shared.Application.Services;
using BlazorAnimation;

namespace TIAMMobileApp
{
    public static class MauiProgram
    {

        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });

            builder.Services.AddMauiBlazorWebView();

#if DEBUG
            builder.Services.AddBlazorWebViewDeveloperTools();
            builder.Logging.AddDebug();
#endif
            builder.Services.AddLocalization();
            var handler = new HttpClientHandler();
            handler.ServerCertificateCustomValidationCallback = (message, certificate, chain, sslPolicyErrors) => true;
            var client = new HttpClient(handler);            
            
            /*Windows*/
            client.BaseAddress = new Uri("https://localhost:7116");
            
            /*Android*/
            //client.BaseAddress = new Uri("https://10.0.2.2:7116");

            builder.Services.AddSingleton(sp => client);

            builder.Services.AddDevExpressBlazor(configure => configure.BootstrapVersion = BootstrapVersion.v5);

            builder.Services.AddScoped<IWeatherForecastService, WeatherForecastService>();
            builder.Services.AddScoped<ITransferDataService, TransferDataService>();
            builder.Services.AddScoped<LogToBrowserConsole>();
            builder.Services.AddScoped<IPopulationStructureDataProvider, PopulationStructureDataProvider>();
            builder.Services.AddScoped<ISupplierService, SupplierService>();
            builder.Services.AddScoped<IUserDataService, UserDataServiceMobile>();
            builder.Services.AddScoped<ISecureStorageHandler, SecureStorageHandler>();            
            builder.Services.AddScoped<ISessionService, SessionServiceMobile>();            
            builder.Services.AddSingleton<IComponentUpdateService, ComponentUpdateServiceMobile>();
            builder.Services.AddScoped<IServiceProviderDataService, ServiceProviderDataService>();
            builder.Services.AddScoped<IClientNoticeSenderService, ClientNoticeSenderService>();
            builder.Services.AddScoped<IWizardProcessor, WizardProcessor>();
            builder.Services.AddScoped<IImageDataService, ImageDataService>();
            builder.Services.AddSingleton(x => new ResourceManager("TIAMWebApp.Shared.Application.Resources", typeof(Main).Assembly));

            builder.Services.Configure<AnimationOptions>(Guid.NewGuid().ToString(), c => { });
            return builder.Build();
        }
    }
}