using System.Text.Json;
using System.Text.Json.Serialization;
using Blazored.LocalStorage;
using Microsoft.Extensions.Logging;
using MudBlazor.Services;
using Services;
using Services.Development;
using Services.Immortal;
using Services.Website;

namespace Device;

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

        builder.Services.AddMauiBlazorWebView();

#if DEBUG
        builder.Services.AddBlazorWebViewDeveloperTools();
        builder.Logging.AddDebug();
#endif

        builder.Services.AddLocalization();

        builder.Services.AddBlazoredLocalStorage(config =>
        {
            config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
            config.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
            config.JsonSerializerOptions.IgnoreReadOnlyProperties = true;
            config.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
            config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
            config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip;
            config.JsonSerializerOptions.WriteIndented = false;
        });


        builder.Services.AddScoped<INavigationService, NavigationService>();
        builder.Services.AddScoped<IKeyService, KeyService>();
        builder.Services.AddScoped<IImmortalSelectionService, ImmortalSelectionService>();
        builder.Services.AddScoped<IBuildComparisonService, DeprecatedBuildComparisionService>();
        builder.Services.AddScoped<IBuildOrderService, BuildOrderService>();
        builder.Services.AddScoped<IEconomyService, EconomyService>();
        builder.Services.AddScoped<ITimingService, TimingService>();
        builder.Services.AddScoped<IMemoryTesterService, MemoryTesterService>();
        builder.Services.AddScoped<IEntityFilterService, EntityFilterService>();
        builder.Services.AddScoped<IEntityDisplayService, EntityDisplayService>();
        builder.Services.AddScoped<IEntityDialogService, EntityDialogService>();
        builder.Services.AddScoped<IGlossaryService, GlossaryService>();
        builder.Services.AddScoped<IGlossaryDialogService, GlossaryDialogService>();
        builder.Services.AddScoped<IToastService, ToastService>();
        builder.Services.AddScoped<INoteService, NoteService>();
        builder.Services.AddScoped<ISearchService, SearchService>();
        builder.Services.AddScoped<IStorageService, StorageService>();
        builder.Services.AddScoped<IPermissionService, PermissionService>();
        builder.Services.AddScoped<IEconomyComparisonService, EconomyComparisionService>();
        builder.Services.AddScoped<IDataCollectionService, DataCollectionService>();

        builder.Services.AddScoped<IMyDialogService, MyDialogService>();
        builder.Services.AddScoped<TechTreeService>();

        builder.Services.AddMudServices();

        builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://0.0.0.0") });

        return builder.Build();
    }
}