//
//  RYCentralManager.h
//  BleKit
//
//  Created by ldc on 2019/3/25.
//  Copyright © 2019 Xiamen Hanin. All rights reserved.
//

#import <CoreBluetooth/CoreBluetooth.h>
#import <RYCommunication/RYBleAccessory.h>

NS_ASSUME_NONNULL_BEGIN

@interface RYCentralManager : NSObject <CBCentralManagerDelegate>

/// 获取蓝牙中心单例
+ (instancetype)share;

/// 蓝牙是否开启
@property (nonatomic,readonly, assign) BOOL isBlePowerOn;

@property (nonatomic, strong, readonly) CBCentralManager *manager;


/// 获取已连接设备
/// - Parameter serviceUUIDs: 服务UUID
- (NSArray<RYBleAccessory *> *)retrieveConnectedPeripheralsWithServices:(NSArray<CBUUID *> *)serviceUUIDs;


/// 通过标识获取设备
/// - Parameter identifiers: 设备标识
- (NSArray<RYBleAccessory *> *)retrievePeripheralsWithIdentifiers:(NSArray<NSUUID *> *)identifiers;


/// 开始搜索，返回搜索任务标识
/// - Parameters:
///   - timeout: 超时时间
///   - discoverBlock: 搜索设备回调
///   - powerOffBlock: 蓝牙关闭回调
///   - scanTimeoutBlock: 搜索超时回调
///   - printerFilter: 设备过滤
- (NSString *)startScan:(NSTimeInterval)timeout
          discoverBlock:(void(^ _Nullable)(RYBleAccessory *device))discoverBlock
          powerOffBlock:(void(^ _Nullable)(void))powerOffBlock
       scanTimeoutBlock:(void(^ _Nullable)(void))scanTimeoutBlock
          printerFilter:(BOOL (^ _Nullable)(CBPeripheral *, NSNumber *, NSDictionary<NSString *,id> *))printerFilter;


/// 停止搜索
/// - Parameter identity: 搜索任务标识
- (void)stopScan:(NSString *)identity;

- (void)registCentralManagerDelegate:(RYBleAccessory *)delegate;

- (void)unregistCentralManagerDelegate:(RYBleAccessory *)delegate;

- (void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary<NSString *, id> *)options;

- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;

@end

NS_ASSUME_NONNULL_END
