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

interface OdpViewManagerCommandMappings {
  startOdp: number | string;
  stopOdp: number | string;
  uploadLogs: number | string;
}

let OdpViewManagerCommands: OdpViewManagerCommandMappings = {
  startOdp: 1,
  stopOdp: 2,
  uploadLogs: 3,
};
if (Platform.OS == 'ios') {
  OdpViewManagerCommands = {
    startOdp: 'startOdp',
    stopOdp: 'stopOdp',
    uploadLogs: 'uploadLogs',
  };
}

export const startOdp = (viewId: number | null, key: string, host: string, interval: number) =>
  UIManager.dispatchViewManagerCommand(
    viewId,
    OdpViewManagerCommands.startOdp.toString(),
    [key, host, interval]
  );

export const stopOdp = (viewId: number | null) =>
  UIManager.dispatchViewManagerCommand(
    viewId,
    OdpViewManagerCommands.stopOdp.toString(),
    []
  );

export const uploadLogs = (viewId: number | null) =>
  UIManager.dispatchViewManagerCommand(
    viewId,
    OdpViewManagerCommands.uploadLogs.toString(),
    []
  );
