//
//  LMCameraCaptureProtocol.h
//  LunaMobile
//
//  Created by michael on 05.05.2023.
//

#ifndef LMCameraCaptureProtocol_h
#define LMCameraCaptureProtocol_h

#import <LunaCore/LunaCore.h>
#import "VideoServiceConsts.h"
/// Handler block for captured buffer handler
typedef void (^CaptureSampleBufferHandler)(CMSampleBufferRef _Nullable);
/// Handler block for captured layer handler
typedef void (^CaptureLayerHandler)(CALayer * _Nullable);
/// Handler block for captured image
typedef void (^CaptureCGImageHandler)(CGImageRef _Nullable image, NSError * _Nullable error);

/// Base protocol for camera capture object
@protocol LMCameraCaptureProtocol <NSObject>

/// Called video capture from telephone camera Вызывает захват видеопотока с камеры телефона.
/// @note Use the previewLayer property to display the video stream on the UI. Use the captureHandler property to capture the frame buffer of the video stream.
/// - Parameter delay: delay time in seconds (NSTimeInterval)
- (void)startWithDelay: (NSTimeInterval) delay;


/// Stops capturing a video stream.
/// @param completion  completion block
- (void)stopWithCompletion: (VoidBlock _Nonnull) completion;

/// Update frame of capture layer
/// @param rect new frame
- (void)updateLayerFrameWithRect: (CGRect) rect;

/// Updates camera orientation according to ui orientation
/// @param orientation ui orientation object
- (void)updateCameraOrientation:(UIInterfaceOrientation) orientation;

///  Configures a video stream capture session.
///  @note If the device does not have a camera in the selected position or does not support the 1280x720 preset, the method returns false.
///  @param cameraPosition Camera position
- (void)configureWithCameraPosition: (AVCaptureDevicePosition)cameraPosition
                         completion: (VoidBlock _Nonnull) completion;

/// Gets camera's preview layer
/// @param bestshotDetector bestshotDetector, providing camera operations
/// @param completion completion block
- (void)findPreviewLayerWithBestshotDetector: (id<LCBestShotDetectorProtocol> _Nonnull) bestshotDetector
                                  completion: (CaptureLayerHandler _Nullable) completion;

/// Changes the camera type between main and front.
- (void)switchCameraType;

/// Set handler of captured sample buffer
/// - Parameter newHandler: sample buffer handler
- (void)defineSampleBufferhandler: (CaptureSampleBufferHandler)newHandler;

/// Set handler of captured image
/// - Parameter newHandler: image handler
- (void)defineCGImageHandler: (CaptureCGImageHandler)newHandler;

@end

#endif /* LMCameraCaptureProtocol_h */
