import { NativeModules } from 'react-native'

import Base from './Base'
import { GizCallback, GizResult, IUpdateAuthorizeDataParams } from './types'

class RNGizUserManagerModule extends Base {
  logout(): Promise<GizResult<any, any>> {
    return this.callbackWapper((callback: GizCallback<any, any>) => {
      NativeModules.RNGizUserManagerModule.logout({}, callback)
    })
  }
  updateAuthorizeData(
    params: IUpdateAuthorizeDataParams
  ): Promise<GizResult<any, any>> {
    return this.callbackWapper((callback: GizCallback<any, any>) => {
      NativeModules.RNGizUserManagerModule.updateAuthorizeData(params, callback)
    })
  }
  getAuthorizeData(): Promise<GizResult<IUpdateAuthorizeDataParams, any>> {
    return this.callbackWapper((callback: GizCallback<any, any>) => {
      NativeModules.RNGizUserManagerModule.getAuthorizeData({}, callback)
    })
  }
  loginByAnonymous(): Promise<GizResult<IUpdateAuthorizeDataParams, any>> {
    return this.callbackWapper((callback: GizCallback<any, any>) => {
      NativeModules.RNGizUserManagerModule.loginByAnonymous({}, callback)
    })
  }
  registerWithAccount(username: string, password: string): Promise<GizResult<IUpdateAuthorizeDataParams, any>> {
    return this.callbackWapper((callback: GizCallback<any, any>) => {
      NativeModules.RNGizUserManagerModule.registerWithAccount({username, password}, callback)
    })
  }
  loginWithAccount(username: string, password: string): Promise<GizResult<IUpdateAuthorizeDataParams, any>> {
    return this.callbackWapper((callback: GizCallback<any, any>) => {
      NativeModules.RNGizUserManagerModule.loginWithAccount({username, password}, callback)
    })
  }

}

export default new RNGizUserManagerModule()

export { RNGizUserManagerModule }