function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { NativeModules } from 'react-native';
import { handleErrorCodes, LINKING_ERROR } from './error';
let initialized = false;
const AuthsignalSMSModule = NativeModules.AuthsignalSMSModule ? NativeModules.AuthsignalSMSModule : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
export class AuthsignalSms {
  constructor(_ref) {
    let {
      tenantID,
      baseURL,
      enableLogging
    } = _ref;
    _defineProperty(this, "tenantID", void 0);
    _defineProperty(this, "baseURL", void 0);
    _defineProperty(this, "enableLogging", void 0);
    this.tenantID = tenantID;
    this.baseURL = baseURL;
    this.enableLogging = enableLogging;
  }
  async enroll(_ref2) {
    let {
      phoneNumber
    } = _ref2;
    await this.ensureModuleIsInitialized();
    try {
      await AuthsignalSMSModule.enroll(phoneNumber);
      return {};
    } catch (ex) {
      return this.handleError(ex);
    }
  }
  async challenge() {
    await this.ensureModuleIsInitialized();
    try {
      await AuthsignalSMSModule.challenge();
      return {};
    } catch (ex) {
      return this.handleError(ex);
    }
  }
  async verify(_ref3) {
    let {
      code
    } = _ref3;
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalSMSModule.verify(code);
      return {
        data
      };
    } catch (ex) {
      return this.handleError(ex);
    }
  }
  async ensureModuleIsInitialized() {
    if (initialized) {
      return;
    }
    await AuthsignalSMSModule.initialize(this.tenantID, this.baseURL);
    initialized = true;
  }
  handleError(ex) {
    if (this.enableLogging) {
      console.log(ex);
    }
    return handleErrorCodes(ex);
  }
}
//# sourceMappingURL=sms.js.map