//
//  BluetoothManager.h
//  CIDPrinterLibrary
//
//  Created by Uwe Hoppe on 20.01.22.
//

#ifndef BluetoothManager_h
#define BluetoothManager_h

#import <Foundation/Foundation.h>
#import "Device.h"

@class Device;

typedef void (^BluetoothManagerDiscoverPeripheralsCallback) (NSArray *peripherals);
typedef void (^BluetoothManagerDiscoverPeripheralsChangesCallback) (Device *peripheral);

@import CoreBluetooth;

@interface BluetoothManager : NSObject

@property (nonatomic, getter = isScanning) BOOL scanning;
@property (assign, nonatomic, readonly, getter = isCentralReady) BOOL centralReady;
@property (assign, nonatomic) NSUInteger peripheralsCountToStop;
@property (weak, nonatomic, readonly) NSString *centralNotReadyReason;
@property (weak, nonatomic, readonly) NSArray *peripherals;
@property (strong, nonatomic, readonly) CBCentralManager *manager;
+ (NSSet *)keyPathsForValuesAffectingCentralReady;
+ (NSSet *)keyPathsForValuesAffectingCentralNotReadyReason;

-(void)scanForPeripheralsWithChanges:(BluetoothManagerDiscoverPeripheralsChangesCallback)changesCallback;
- (void)scanForPeripherals;
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options;
- (void)scanForPeripheralsByInterval:(NSUInteger)scanInterval changes:(BluetoothManagerDiscoverPeripheralsChangesCallback)changesCallback callback:(BluetoothManagerDiscoverPeripheralsCallback)callback;
- (void)scanForPeripheralsByInterval:(NSUInteger)scanInterval callback:(BluetoothManagerDiscoverPeripheralsCallback)callback;
- (void)scanForPeripheralsByInterval:(NSUInteger)scanInterval services:(NSArray *)serviceUUIDs options:(NSDictionary *)options callback:(BluetoothManagerDiscoverPeripheralsCallback)callback;
- (void)stopScanForPeripherals;
- (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers;
- (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDS;

+ (BluetoothManager *)sharedInstance;

@end

#endif /* BluetoothManager_h */
