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

interface Recognition {
  frameId: number,
  recognitions: string,
  lat: number,
  lng: number,
  processTime: number,
  receivedTime: number
}

interface DetectedSign {
  id: number,
  label: string,
  lat: number,
  lng: number,
  serialized: string
}

const LINKING_ERROR =
  `The package 'xsign-post-processing' 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 managed workflow\n';

const XsignPostProcessing = NativeModules.XsignPostProcessing
  ? NativeModules.XsignPostProcessing
  : new Proxy(
      {},
      {
        get() {
          throw new Error(LINKING_ERROR);
        },
      }
    );

export function multiply(a: number, b: number): Promise<number> {
  return XsignPostProcessing.multiply(a, b);
}

export function detectSign(data: Recognition[], imgWidth: number): Promise<DetectedSign[]> {
  return XsignPostProcessing.detectSign(data, imgWidth);
}
