package com.yidian.shenghuoquan.newscontent.http

import com.google.gson.reflect.TypeToken
import com.yidian.bcommon.YdBaseApplication
import com.yidian.bcommon.bean.LifeAccountItemBean
import com.yidian.bcommon.http.HttpParamsUtils
import com.yidian.bcommon.http.HttpResult
import com.yidian.bcommon.http.HttpResultSubscriber
import com.yidian.bcommon.http.TransformUtil
import com.yidian.http.ServiceFactory
import com.yidian.shenghuoquan.newscontent.bean.ICreateLifeAccountCallback
import com.yidian.shenghuoquan.newscontent.http.callback.*
import com.yidian.shenghuoquan.newscontent.http.httpbean.*
import com.yidian.utils.ToastUtil
import okhttp3.MultipartBody

class ApiService {
  companion object {

    // 文件上传
    fun uploadFile(apiCallback: IUploadFileCallback, requestParams: MultipartBody.Part) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .uploadFile(publicParamsMap, requestParams)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.uploadFileCallBack(result)
          }

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

        })
    }

    // pushToken绑定接口
    fun pushTokenAndroid(requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .pushTokenAndroid(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {

          }

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

          }
        })
    }

    // 获取短信验证码
    fun sendMsgCode(apiCallback: IMobileLoginCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .sendMsgCode(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.sendSmsCodeCallBack(result)
          }

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

    // 手机号登录接口
    fun mobileLogin(apiCallback: IMobileLoginCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .mobileLogin(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<MobileLoginBean.Response?>() {
          override fun onSuccess(result: HttpResult<MobileLoginBean.Response?>?) {
            apiCallback.mobileLoginCallBack(result)
          }

          override fun onFailure(result: HttpResult<MobileLoginBean.Response?>?) {
            apiCallback.mobileLoginCallBack(result)
          }
        })
    }

    // 用户退出登录接口
    fun userLogout(apiCallback: IUserLogoutCallBack) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(HashMap(), timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .userLogout(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.userLogoutSuccess()
          }

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

    // 101 身份信息校验接口
    fun authPersonalCheck(apiCallback: IAuthPersonalCheckCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authPersonalCheck(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any>() {
          override fun onSuccess(result: HttpResult<Any>?) {
            apiCallback.authPersonCheckSuccess()
          }

          override fun onFailure(result: HttpResult<Any>?) {
            apiCallback.authPersonCheckFailure(result?.code, result?.reason)
          }
        })
    }

    // 102 活体识别成功后回调接口
    fun authLiveIdentity(apiCallback: IAuthLiveIdentityCallback) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(HashMap(), timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authLiveIdentity(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.authLiveIdentitySuccess()
          }

          override fun onFailure(result: HttpResult<Any?>?) {
            apiCallback.authLiveIdentityFailure(result?.reason)
          }
        })
    }

    // 103 认证完成后创建生活号接口
    fun authComplete(apiCallbackPersonal: IAuthPersonalCompleteCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authComplete(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthPersonalCompleteBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthPersonalCompleteBean.Response?>?) {
            apiCallbackPersonal.authPersonalCompleteSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<AuthPersonalCompleteBean.Response?>?) {
            apiCallbackPersonal.authPersonalCompleteFailure(result?.reason)
          }
        })
    }

    // 104 检测是否可以个人认证，返回认证信息接口
    fun authAuthentication(apiCallback: IAuthAuthenticationCallback) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(HashMap(), timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authAuthentication(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthAuthenticationBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthAuthenticationBean.Response?>?) {
            apiCallback.authAuthenticationSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<AuthAuthenticationBean.Response?>?) {
            apiCallback.authAuthenticationFailure(result?.reason)
          }
        })
    }

    // 106 获取生活号列表接口
    fun getLifeAccountList(apiCallback: IGetLifeAccountListCallback) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(HashMap(), timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .getAccountList(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<ArrayList<LifeAccountItemBean.Response>?>() {
          override fun onSuccess(result: HttpResult<ArrayList<LifeAccountItemBean.Response>?>?) {
            apiCallback.getLifeAccountListSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<ArrayList<LifeAccountItemBean.Response>?>?) {
            apiCallback.getLifeAccountListFailure(result?.reason)
          }
        })
    }

    // 201 身份证OCR接口
    fun getIDCardOCR(apiCallback: IGetIDCardOCRCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .getIDCardOCR(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<GetIDCardOCRBean.Response>() {
          override fun onSuccess(result: HttpResult<GetIDCardOCRBean.Response>?) {
            apiCallback.getIDCardOCRSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<GetIDCardOCRBean.Response>?) {
            apiCallback.getIDCardOCRFailure(result?.reason)
          }
        })
    }

    // 202 获取人脸检测token接口
    fun authPersonalGetToken(apiCallback: AuthPersonalGetTokenCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authPersonalGetToken(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthPersonalGetTokenBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthPersonalGetTokenBean.Response?>?) {
            apiCallback.getTokenSuccess(result)
          }

          override fun onFailure(result: HttpResult<AuthPersonalGetTokenBean.Response?>?) {
          }
        })
    }

    // 203 人脸检测接口
    fun identifyIdOcrVerify(apiCallback: IdentifyIdOcrVerifyCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .identifyIdOcrVerify(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<IdentifyIdOcrVerifyBean.Response?>() {
          override fun onSuccess(result: HttpResult<IdentifyIdOcrVerifyBean.Response?>?) {
            apiCallback.identifyIdOcrVerifySuccess(result)
          }

          override fun onFailure(result: HttpResult<IdentifyIdOcrVerifyBean.Response?>?) {
            apiCallback.identifyIdOcrVerifyFailure(result)
          }
        })
    }

    // 204 营业执照OCR接口
    fun businessLicenseOCR(apiCallback: IBusinessLicenseOCRCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .businessLicenseOCR(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<BusinessLicenseOCRBean.Response>() {
          override fun onSuccess(result: HttpResult<BusinessLicenseOCRBean.Response>?) {
            apiCallback.businessLicenseOCRSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<BusinessLicenseOCRBean.Response>?) {
            apiCallback.businessLicenseOCRFailure(result?.reason)
          }
        })
    }

    // 301 获取金山云token接口
    fun getKSYunToken(requestParams: HashMap<String, String?>): HttpResult<GetKSYunTokenBean.Response>? {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      val res: HttpResult<Any?>? = ServiceFactory.getInstance().createService(CommonService::class.java)
        .getKSYunToken(publicParamsMap, privateParamsMap)
        .execute().body()
      if (res?.code == 0) {
        return HttpParamsUtils.rsaDecryptResult(res, object : TypeToken<GetKSYunTokenBean.Response>() {}.type)
      } else {
        val decodeResult = HttpResult<GetKSYunTokenBean.Response>()
        decodeResult.code = res?.code!!
        decodeResult.reason = res.reason
        decodeResult.status = res.status
        ToastUtil.showToast(YdBaseApplication.context, res.reason)
      }
      return null
    }

    // 302 获取金山云ObjectId和Bucket接口
    fun getKSYunObjectId(apiCallback: IGetKSYunObjectIdCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .getKSYunObjectId(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<GetKSYunObjectIdBean.Response>() {
          override fun onSuccess(result: HttpResult<GetKSYunObjectIdBean.Response>?) {
            apiCallback.getKSYunObjectIdSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<GetKSYunObjectIdBean.Response>?) {
            apiCallback.getKSYunObjectIdFailure(result?.reason)
          }
        })
    }

    // 401 商户认证检查接口
    fun authMerchantCheck(apiCallback: IAuthMerchantCheckCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authMerchantCheck(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthMerchantCheckBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthMerchantCheckBean.Response?>?) {
            apiCallback.authMerchantCheckSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<AuthMerchantCheckBean.Response?>?) {
            apiCallback.authMerchantCheckFailure(result?.reason)
          }
        })
    }

    // 402 商户上传营业执照信息接口
    fun authBusinessLicenseCommit(apiCallback: IAuthBusinessLicenseCommitCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authBusinessLicenseCommit(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthBusinessLicenseCommitBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthBusinessLicenseCommitBean.Response?>?) {
            apiCallback.authBusinessLicenseCommitSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<AuthBusinessLicenseCommitBean.Response?>?) {
            apiCallback.authBusinessLicenseCommitFailure(result?.reason)
          }
        })
    }

    // 403 普通企业上传法人身份信息接口
    fun authEnterpriseLegalIdentityCommit(
      apiCallback: IAuthEnterpriseLegalIdentityCommitCallback,
      requestParams: HashMap<String, String?>
    ) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authEnterpriseLegalIdentityCommit(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthEnterpriseLegalIdentityCommitBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthEnterpriseLegalIdentityCommitBean.Response?>?) {
            apiCallback.authEnterpriseLegalIdentityCommitSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<AuthEnterpriseLegalIdentityCommitBean.Response?>?) {
            apiCallback.authEnterpriseLegalIdentityCommitFailure(result?.reason)
          }
        })
    }

    // 404 个体工商户身份认证接口
    fun authIndividualBusinessIdentityCommit(
      apiCallback: IAuthIndividualBusinessIdentityCommitCallback,
      requestParams: HashMap<String, String?>
    ) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authIndividualBusinessIdentityCommit(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.authIndividualBusinessIdentityCommitSuccess()
          }

          override fun onFailure(result: HttpResult<Any?>?) {
            apiCallback.authIndividualBusinessIdentityCommitFailure(result?.reason)
          }
        })
    }

    // 405 活体识别成功后回调接口
    fun authEnterpriseLiveIdentity(apiCallback: IAuthEnterpriseLiveIdentityCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authEnterpriseLiveIdentity(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.authEnterpriseLiveIdentitySuccess()
          }

          override fun onFailure(result: HttpResult<Any?>?) {
            apiCallback.authEnterpriseLiveIdentityFailure(result?.reason)
          }
        })
    }

    // 406 个体工商户认证完成接口
    fun authIndividualBusinessComplete(apiCallback: IAuthIndividualBusinessCompleteCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .authIndividualBusinessComplete(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<AuthIndividualBusinessCompleteBean.Response?>() {
          override fun onSuccess(result: HttpResult<AuthIndividualBusinessCompleteBean.Response?>?) {
            apiCallback.authIndividualBusinessCompleteSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<AuthIndividualBusinessCompleteBean.Response?>?) {
            apiCallback.authIndividualBusinessCompleteFailure(result?.reason)
          }
        })
    }

    // 407 生活号名检查与修改接口
    fun createLifeAccount(apiCallback: ICreateLifeAccountCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .createLifeAccount(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            apiCallback.createLifeAccountCallback(true)
          }

          override fun onFailure(result: HttpResult<Any?>?) {
            apiCallback.createLifeAccountCallback(false)
          }
        })
    }

    // 418 根据生活号id返回认证信息
    fun getLifeAccountInfoById(apiCallback: IGetLifeAccountInfoByIdCallback, requestParams: HashMap<String, String?>) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .getLifeAccountInfoById(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<GetLifeAccountInfoByIdBean.Response?>() {
          override fun onSuccess(result: HttpResult<GetLifeAccountInfoByIdBean.Response?>?) {
            apiCallback.getLifeAccountInfoByIdSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<GetLifeAccountInfoByIdBean.Response?>?) {
            apiCallback.getLifeAccountInfoByIdFailure(result?.reason)
          }
        })
    }

    // 521 管理中心开关接口
    fun getConfigList(apiCallback: IGetConfigListCallback) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(HashMap(), timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .getConfigList(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<GetConfigListBean.Response>() {
          override fun onSuccess(result: HttpResult<GetConfigListBean.Response>?) {
            apiCallback.getConfigListSuccess(result?.result)
          }

          override fun onFailure(result: HttpResult<GetConfigListBean.Response>?) {
            apiCallback.getConfigListFailure(result?.reason)
          }

        })
    }

    // 新建门店
    fun addStore(requestParams: HashMap<String, String?>, callback: ((Boolean) -> Unit)? = null) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .addShop(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            callback?.invoke(true)
          }

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

          }
        })
    }

    // 编辑门店
    fun updateStore(requestParams: HashMap<String, String?>, callback: ((Boolean) -> Unit)? = null) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .updateShop(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<Any?>() {
          override fun onSuccess(result: HttpResult<Any?>?) {
            callback?.invoke(true)
          }

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

          }
        })
    }

    fun getShopList(requestParams: HashMap<String, String?>, callback: ((ArrayList<GetShopListBean>) -> Unit)? = null) {
      val timeStamp = System.currentTimeMillis()
      val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
      val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
      ServiceFactory.getInstance().createService(CommonService::class.java)
        .getShopList(publicParamsMap, privateParamsMap)
        .compose(TransformUtil.defaultSchedulers())
        .subscribe(object : HttpResultSubscriber<ArrayList<GetShopListBean>?>() {
          override fun onSuccess(result: HttpResult<ArrayList<GetShopListBean>?>?) {
            callback?.invoke(result!!.result!!)
          }

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

  }
}
