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

const LINKING_ERROR =
  `The package 'react-native-facetec' 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 Facetec = NativeModules.Facetec
  ? NativeModules.Facetec
  : new Proxy(
      {},
      {
        get() {
          throw new Error(LINKING_ERROR);
        },
      }
    );

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

export function init(DeviceKey: string, colors: object, messages: object, apiUrl: string, logo: boolean): Promise<Boolean> {
  return Facetec.init(DeviceKey, colors, messages, apiUrl, logo);
}

export function liveness() {
  return Facetec.liveness();
}

export function photoMatch(): Promise<String> {
  return Facetec.photoMatch();
}

export function authenticate(externalReferenceId: string): Promise<String> {
  return Facetec.authenticate(externalReferenceId);
}
