//
//  CameraUtility.h
//  AIIM
//
//  Created by qitewei on 2025/6/5.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <MobileCoreServices/MobileCoreServices.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, CameraUtilityFlashMode) {
    CameraUtilityFlashModeOff  = 0,
    CameraUtilityFlashModeOn   = 1,
    CameraUtilityFlashModeAuto = 2
};

typedef NS_ENUM(NSInteger, CameraAspectRatioMode) {
    CameraAspectRatioModeOriginal,    // 原始比例
    CameraAspectRatioModeScreen,      // 匹配屏幕比例
    CameraAspectRatioModeSquare       // 正方形(可选)
};

@protocol CameraUtilityDelegate <NSObject>

@optional
- (void)cameraUtilityDidFinishTakingPhoto:(UIImage *)photo;
- (void)cameraUtilityDidFinishRecordingVideo:(NSURL *)videoURL;
- (void)cameraUtilityDidOccurError:(NSError *)error;
- (void)cameraUtilityRecordingProgress:(CGFloat)progress;

@end

@interface CameraUtility : NSObject
@property (nonatomic, weak) id<CameraUtilityDelegate> delegate;
@property (nonatomic, assign) CameraUtilityFlashMode flashMode;
@property (nonatomic, assign) CameraAspectRatioMode aspectRatioMode;
@property (nonatomic, assign) BOOL isFrontCamera;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer;
@property (nonatomic, strong, readonly) NSURL *lastVideoOutputURL;
@property (nonatomic, copy) NSString *videoSaveDirectory; // 自定义保存目录

// 初始化方法
- (instancetype)initWithPreviewView:(UIView *)previewView;

// 配置拍摄按钮（处理单击和长按手势）
- (void)configureCaptureButton:(UIButton *)button;

// 开始运行摄像头
- (void)startRunning;
// 停止运行摄像头
- (void)stopRunning;

// 切换摄像头
- (void)switchCamera;

// 手动拍照
- (void)takePhoto;

// 开始录制视频
- (void)startRecordingVideo;
// 停止录制视频
- (void)stopRecordingVideo;

// 清除临时文件
- (void)cleanTempFiles;
@end

NS_ASSUME_NONNULL_END
