"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AuthsignalPush = 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 AuthsignalPushModule = _reactNative.NativeModules.AuthsignalPushModule ? _reactNative.NativeModules.AuthsignalPushModule : new Proxy({}, {
  get() {
    throw new Error(_error.LINKING_ERROR);
  }
});
class AuthsignalPush {
  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 getCredential() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalPushModule.getCredential();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return (0, _error.handleErrorCodes)(ex);
    }
  }
  async addCredential() {
    let {
      token,
      requireUserAuthentication = false,
      keychainAccess
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    await this.ensureModuleIsInitialized();
    try {
      const data = _reactNative.Platform.OS === 'ios' ? await AuthsignalPushModule.addCredential(token, requireUserAuthentication, keychainAccess) : await AuthsignalPushModule.addCredential(token);
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return (0, _error.handleErrorCodes)(ex);
    }
  }
  async removeCredential() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalPushModule.removeCredential();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return (0, _error.handleErrorCodes)(ex);
    }
  }
  async getChallenge() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalPushModule.getChallenge();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return (0, _error.handleErrorCodes)(ex);
    }
  }
  async updateChallenge(_ref2) {
    let {
      challengeId,
      approved,
      verificationCode = null
    } = _ref2;
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalPushModule.updateChallenge(challengeId, approved, verificationCode);
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return (0, _error.handleErrorCodes)(ex);
    }
  }
  async ensureModuleIsInitialized() {
    if (initialized) {
      return;
    }
    await AuthsignalPushModule.initialize(this.tenantID, this.baseURL);
    initialized = true;
  }
}
exports.AuthsignalPush = AuthsignalPush;
//# sourceMappingURL=push.js.map