#include "Common.h"

#import <AVFoundation/AVFoundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
 * Filters and sorts AVCaptureDeviceFormat objects based on aspect ratio preferences and resolution targets.
 *
 * This class prioritizes formats by:
 * 1. Matching preferred aspect ratios (within tolerance)
 * 2. Proximity to target pixel count
 * 3. Meeting minimum pixel count threshold
 */
JDACLIENT_EXPORT @interface JDACameraFormatFilter : NSObject

/** Ordered list of preferred aspect ratios (e.g., @[@(16.0/9.0), @(4.0/3.0)]). Non-matching resolutions will be placed last in the sequence. */
@property (nonatomic) NSArray<NSNumber*>* preferredAspectRatios;

/** Floating point precision tolerance for aspect ratio matching. */
@property (nonatomic) CGFloat aspectRatioMatchTolerance;

/** Target resolution in pixels. Formats closest to this value are ordered first in the sequence. */
@property (nonatomic) NSUInteger targetPixelCount;

/** Minimum resolution threshold in pixels. Formats below this are excluded. */
@property (nonatomic) NSUInteger minimumPixelCount;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

/**
 * Designated initializer.
 *
 * @param preferredAspectRatios Ordered list of aspect ratios to prioritize
 * @param aspectRatioMatchTolerance Tolerance for aspect ratio matching
 * @param targetPixelCount Target resolution for sorting by proximity
 * @param minimumPixelCount Minimum resolution threshold for filtering
 */
- (instancetype)initWithPreferredAspectRatios:(NSArray<NSNumber*>*)preferredAspectRatios aspectRatioMatchTolerance:(CGFloat)aspectRatioMatchTolerance targetPixelCount:(NSUInteger)targetPixelCount minimunPixelCount:(NSUInteger)minimumPixelCount NS_DESIGNATED_INITIALIZER;

/** Convenience factory method. */
+ (instancetype)filterWithPreferredAspectRatios:(NSArray<NSNumber*>*)preferredAspectRatios aspectRatioMatchTolerance:(CGFloat)aspectRatioMatchTolerance targetPixelCount:(NSUInteger)targetPixelCount minimumPixelCount:(NSUInteger)minimumPixelCount;

/**
 * Filters and sorts camera formats based on configured criteria.
 *
 * @param formats Input array of AVCaptureDeviceFormat objects
 * @return Filtered and sorted array of formats
 */
- (NSArray<AVCaptureDeviceFormat*>*)filterFormats:(NSArray<AVCaptureDeviceFormat*>*)formats;

@end

NS_ASSUME_NONNULL_END