using Common.Library;
using GreadyPoang.CommandClasses;
using GreadyPoang.DataLayer;
using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using GreadyPoang.Views;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace GreadyPoang;

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.AddDbContext<DataContext>(options =>
        {
            var MauiDataPath = FileSystem.Current.AppDataDirectory;
            if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ;
            {
                File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath);
            }
            var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
            options.UseSqlite($"Data Source={dbPath}");
        });

        builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>();
        builder.Services.AddScoped<ParticipantViewModelCommands>();
        builder.Services.AddScoped<ParticipantListView>();

        builder.Services.AddScoped<IRepository<GameRound>, GameRoundRepository>();
        builder.Services.AddScoped<RoundStartingViewModelCommands>();
        builder.Services.AddScoped<RoundStartingView>();

        builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();

        builder.Services.AddScoped<RoundRunningViewModelCommands>();
        builder.Services.AddScoped<RoundRunningView>();

        builder.Services.AddScoped<IRepository<GamePoint>, GamePointRepository>();


        builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();

        builder.Services.AddScoped<ICombinedRepository, CombinedRepository>();

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

        return builder.Build();
    }
}
