package com.yidian.shenghuoquan.bgeneralbusiness.http

import com.yidian.bcommon.http.*
import com.yidian.http.ServiceFactory

object GeneralBusinessRemoteDataService {

  private var api = ServiceFactory.getInstance().createService(GeneralBusinessApiService::class.java)

  // 获取短信验证码
  fun sendMsgCode(requestParams: HashMap<String, String?>, callback: ((Boolean) -> Unit)? = null) {
    val timeStamp = System.currentTimeMillis()
    val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
    val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
    api.sendMsgCode(publicParamsMap, privateParamsMap)
      .compose(TransformUtil.defaultSchedulers())
      .subscribe(object : HttpResultSubscriber<Any?>() {
        override fun onSuccess(result: HttpResult<Any?>?) {
          callback?.invoke(true)
        }

        override fun onFailure(result: HttpResult<Any?>?) {
        }
      })
  }
}
