using Microsoft.Extensions.Logging;
using LocationTrackerApp.Services;
using LocationTrackerApp.Data;
using LocationTrackerApp.ViewModels;
using LocationTrackerApp.Views;

namespace LocationTrackerApp;

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");
			});

		// Configure logging
#if DEBUG
		builder.Logging.AddDebug();
#endif

		// Register services
		builder.Services.AddSingleton<LocationDbContext>(provider =>
		{
			var dbPath = Path.Combine(FileSystem.AppDataDirectory, "location_tracker.db");
			return new LocationDbContext(dbPath);
		});

		builder.Services.AddSingleton<ILocationService, LocationService>();
		builder.Services.AddSingleton<IConfigurationService, ConfigurationService>();

		// Register view models
		builder.Services.AddTransient<MainViewModel>();

		// Register views
		builder.Services.AddTransient<MainView>();

		return builder.Build();
	}
}
