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, Platform } from 'react-native';
import { handleErrorCodes, LINKING_ERROR } from './error';
let initialized = false;
const AuthsignalPushModule = NativeModules.AuthsignalPushModule ? NativeModules.AuthsignalPushModule : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
export 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 handleErrorCodes(ex);
    }
  }
  async addCredential() {
    let {
      token,
      requireUserAuthentication = false,
      keychainAccess
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    await this.ensureModuleIsInitialized();
    try {
      const data = Platform.OS === 'ios' ? await AuthsignalPushModule.addCredential(token, requireUserAuthentication, keychainAccess) : await AuthsignalPushModule.addCredential(token);
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async removeCredential() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalPushModule.removeCredential();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async getChallenge() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalPushModule.getChallenge();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return 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 handleErrorCodes(ex);
    }
  }
  async ensureModuleIsInitialized() {
    if (initialized) {
      return;
    }
    await AuthsignalPushModule.initialize(this.tenantID, this.baseURL);
    initialized = true;
  }
}
//# sourceMappingURL=push.js.map