using Ninject;
using VisionBuilder.UI.Common;
using VisionBuilder.UI.Common.Plugins;
using VisionBuilder.UI.Common.Processing;
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;

namespace LindtLeerformPlugin;

public class Plugin : IPlugin
{
    public void RegisterGlobalModules(IKernel kernel)
    {
        kernel.Rebind<IRecipeCreationTool>().To<LeerformRecipeCreationTool>().InSingletonScope();
    }

    public void RegisterCameraModules(IKernel kernel, string cameraName)
    {
        kernel.Bind<LeerformSettings, ISettings>().ToConstant(new LeerformSettings(cameraName));

        // Remove existing recognition settings ISettings binding before rebinding
        var existingRecognitionControlSettings = kernel.GetBindings(typeof(BaseRecognitionControlSettings)).First();
        var toRemove = kernel.GetBindings(typeof(ISettings))
            .First(x => x.ProviderCallback.Target == existingRecognitionControlSettings.ProviderCallback.Target);
        kernel.RemoveBinding(toRemove);

        kernel.Bind<LeerformRecognitionControlSettings, BaseRecognitionControlSettings, ISettings>()
            .ToConstant(new LeerformRecognitionControlSettings(cameraName));
        kernel.Rebind<IRecognitionControl>()
            .To<LeerformRecognitionControl>()
            .InSingletonScope();

        kernel.RegisterModule<LeerformModule>();
    }
}
