#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface RCT_EXTERN_MODULE (SdkBle, RCTEventEmitter)

// Scanning
RCT_EXTERN_METHOD(startScan
                  : (NSDictionary *)options resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(stopScan
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Connection management
RCT_EXTERN_METHOD(connect
                  : (NSString *)deviceId resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(disconnect
                  : (NSString *)deviceId resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(isConnected
                  : (NSString *)deviceId resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getConnectedDevices
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Service discovery
RCT_EXTERN_METHOD(discoverServices
                  : (NSString *)deviceId resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Characteristic operations
RCT_EXTERN_METHOD(readCharacteristic
                  : (NSString *)deviceId serviceUuid
                  : (NSString *)serviceUuid characteristicUuid
                  : (NSString *)characteristicUuid resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(writeCharacteristic
                  : (NSString *)deviceId serviceUuid
                  : (NSString *)serviceUuid characteristicUuid
                  : (NSString *)characteristicUuid data
                  : (NSString *)data options
                  : (NSDictionary *)options resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(setNotify
                  : (NSString *)deviceId serviceUuid
                  : (NSString *)serviceUuid characteristicUuid
                  : (NSString *)characteristicUuid enable
                  : (BOOL)enable resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Permissions and state
RCT_EXTERN_METHOD(requestPermissions
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(isBluetoothEnabled
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(enableBluetooth
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Utility
RCT_EXTERN_METHOD(base64ToHexDash
                  : (NSString *)base64 resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Infusion control
RCT_EXTERN_METHOD(startInfusion
                  : (NSString *)deviceId resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(stopInfusion
                  : (NSString *)deviceId resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(setInfusionLevel
                  : (NSString *)deviceId level
                  : (nonnull NSNumber *)level resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// User role
RCT_EXTERN_METHOD(setUserRole
                  : (NSString *)role resolve
                  : (RCTPromiseResolveBlock)resolve reject
                  : (RCTPromiseRejectBlock)reject)

// Event emitter
RCT_EXTERN_METHOD(addListener : (NSString *)eventName)
RCT_EXTERN_METHOD(removeListeners : (double)count)

+ (BOOL)requiresMainQueueSetup {
  return NO;
}

@end
