"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AuthsignalTotp = void 0;
var _reactNative = require("react-native");
var _error = require("./error");
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; }
let initialized = false;
const AuthsignalTOTPModule = _reactNative.NativeModules.AuthsignalTOTPModule ? _reactNative.NativeModules.AuthsignalTOTPModule : new Proxy({}, {
  get() {
    throw new Error(_error.LINKING_ERROR);
  }
});
class AuthsignalTotp {
  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() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalTOTPModule.enroll();
      return {
        data
      };
    } catch (ex) {
      return this.handleError(ex);
    }
  }
  async verify(_ref2) {
    let {
      code
    } = _ref2;
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalTOTPModule.verify(code);
      return {
        data
      };
    } catch (ex) {
      return this.handleError(ex);
    }
  }
  async ensureModuleIsInitialized() {
    if (initialized) {
      return;
    }
    await AuthsignalTOTPModule.initialize(this.tenantID, this.baseURL);
    initialized = true;
  }
  handleError(ex) {
    if (this.enableLogging) {
      console.log(ex);
    }
    return (0, _error.handleErrorCodes)(ex);
  }
}
exports.AuthsignalTotp = AuthsignalTotp;
//# sourceMappingURL=totp.js.map