using Inspectron.Settings;
using Ninject;
using Ninject.Extensions.ChildKernel;
using System.ComponentModel;
using VisionBuilder.UI.Common.NullClasses;
using VisionBuilder.UI.Common.Plugins;
using VisionBuilder.UI.Common.ViewModel;
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;

namespace VisionBuilder.UI.Common;

public static class VisionBuilder
{
    private static Mutex? _mutex;
    const string mutexName = "VisionBuilder.UI.SingleInstance";
    public static bool IsAlreadyRunning()
    {
        _mutex = new Mutex(true, mutexName, out bool createdNew);

        if (!createdNew)
        {
            return true;
        }

        return false;
    }
    public static IKernel CreateMainKernel(InspectronSettings settings)
    {
        TypeDescriptor.AddAttributes(typeof(List<ErrorShortName>), new TypeConverterAttribute(typeof(ErrorShortNameConverter)));

        StandardKernel mainKernel = new StandardKernel();

        // GLOBAL SETTINGS //
        mainKernel.Bind<InspectronSettings>().ToConstant(settings);
        mainKernel.Bind<UIConfiguration, ISettings>().ToConstant(new UIConfiguration());
        mainKernel.Bind<ILearningTool>().To<NoLearning>().InSingletonScope();
        mainKernel.Bind<IRecipeCreationTool>().To<NoRecipeCreation>().InSingletonScope();
        // --- //

        mainKernel.Bind<MainWindowVM>().ToSelf().InSingletonScope();
        return mainKernel;
    }



}