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 AuthsignalDeviceModule = NativeModules.AuthsignalDeviceModule ? NativeModules.AuthsignalDeviceModule : new Proxy({}, {
  get() {
    throw new Error(LINKING_ERROR);
  }
});
export class AuthsignalDevice {
  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 AuthsignalDeviceModule.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 AuthsignalDeviceModule.addCredential(token, requireUserAuthentication, keychainAccess) : await AuthsignalDeviceModule.addCredential(token);
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async removeCredential() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalDeviceModule.removeCredential();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async getChallenge() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalDeviceModule.getChallenge();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async claimChallenge(_ref2) {
    let {
      challengeId
    } = _ref2;
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalDeviceModule.claimChallenge(challengeId);
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async updateChallenge(_ref3) {
    let {
      challengeId,
      approved,
      verificationCode = null
    } = _ref3;
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalDeviceModule.updateChallenge(challengeId, approved, verificationCode);
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async verify() {
    await this.ensureModuleIsInitialized();
    try {
      const data = await AuthsignalDeviceModule.verify();
      return {
        data
      };
    } catch (ex) {
      if (this.enableLogging) {
        console.log(ex);
      }
      return handleErrorCodes(ex);
    }
  }
  async ensureModuleIsInitialized() {
    if (initialized) {
      return;
    }
    await AuthsignalDeviceModule.initialize(this.tenantID, this.baseURL);
    initialized = true;
  }
}
//# sourceMappingURL=device.js.map