import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
  `The package 'react-native-weight-scale-bridge' doesn't seem to be linked. Make sure:\n\n` +
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
  '- You rebuilt the app after installing the package\n' +
  '- You are not using Expo Go\n';

// Changed to match the native module name
const WeightScaleBridge = NativeModules.WeightScaleBridge;

if (!WeightScaleBridge) {
  throw new Error(LINKING_ERROR);
}

export const startScanning = () =>
  WeightScaleBridge.startScanning();

export const stopScanning = () =>
  WeightScaleBridge.stopScanning();

export const calculateBMI = (weight: number, heightCm: number) =>
  WeightScaleBridge.calculateBMI(weight, heightCm);

export const isBluetoothEnabled = () =>
  WeightScaleBridge.isBluetoothEnabled();