using Hawkeye.VisionBuilder.UI.Sources.Emulation;
using Hawkeye.VisionBuilder.UI.Sources.Hawkeye;
using Hawkeye.VisionBuilder.UI.Sources.Raspberry.Libcamera;
using Inspectron.Camera.UEye;
using Ninject;
using Ninject.Extensions.ChildKernel;
using VisionBuilder.UI.Common;
using VisionBuilder.UI.Common.Processing;

namespace VisionBuilder.UI.Camera;

public static class ModuleExtensions
{
    public static IChildKernel RegisterCamera(this IChildKernel self, string cameraName)
    {
        self.Bind<CameraSettings, ISettings>().ToConstant(new CameraSettings(cameraName));
        self.Bind<EmulationSettings, ISettings>().ToConstant(new EmulationSettings(cameraName));
        self.Bind<HawkeyeSettings, ISettings>().ToConstant(new HawkeyeSettings(cameraName));
        self.Bind<IDSImageSourceSettings, ISettings>().ToConstant(new IDSImageSourceSettings(cameraName));
        self.Bind<LibcameraCaptureSettings, ISettings>().ToConstant(new LibcameraCaptureSettings(cameraName));
        self.Bind<SingleCameraVM>().ToSelf().InSingletonScope();
        return self;
    }
    private static void BindCameras(CameraSettings cameraSettings, IChildKernel kernel)
    {
        switch (cameraSettings.CameraSource)
        {
            case CameraSettings.EImageSource.Emulation:
                
                kernel.Bind<IImageSource, IVisionBuilderModule>().To<EmulationCameraImageSource>().InSingletonScope();
                break;
            case CameraSettings.EImageSource.Hawkeye:
                kernel.Bind<IImageSource, IVisionBuilderModule>().To<HawkeyeCameraImageSource>().InSingletonScope();
                break;
            case CameraSettings.EImageSource.IDS:
                kernel.Bind<IImageSource, IVisionBuilderModule>().To<IDSImageSource>().InSingletonScope();
                break;
            case CameraSettings.EImageSource.Libcamera:
                kernel.Bind<IImageSource, IVisionBuilderModule>().To<LibcameraImageSource>().InSingletonScope();
                break;
            case CameraSettings.EImageSource.Basler:
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }
    public static IChildKernel UseCamera(this IChildKernel self)
    {
        var cameraSettings = self.Get<CameraSettings>();
        BindCameras(cameraSettings, self);
        return self;
    }
}