package com.yidian.shenghuoquan.buserorder.http

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.buserorder.app.bean.OrderWebData
import com.yidian.shenghuoquan.buserorder.http.callback.OrderListCallBack
import timber.log.Timber

object UserOrderListOperation {
  private var userOrderListApi = ServiceFactory.getInstance().createService(UserOrderListService::class.java)
  fun userOrderList(requestParams: HashMap<String, String?>, callBack: OrderListCallBack) {
    val timeStamp = System.currentTimeMillis()
    val publicParamsMap = HttpParamsUtils.getPublicParamsMap(timeStamp)
    val privateParamsMap = HttpParamsUtils.getPrivateParamsMap(requestParams, timeStamp)
    userOrderListApi.userOrderList(publicParamsMap, privateParamsMap)
      .compose(TransformUtil.defaultSchedulers())
      .subscribe(object : HttpResultSubscriber<List<OrderWebData>?>() {
        override fun onSuccess(result: HttpResult<List<OrderWebData>?>?) {
          Timber.tag("UserOrderListOperation").i("onSuccess ${result?.result.toString()}")
          callBack.onOrderListCallback(result!!.result)
        }

        override fun onFailure(result: HttpResult<List<OrderWebData>?>?) {
          Timber.tag("UserOrderListOperation").i("onFailure ${result?.result.toString()}")
        }
      })
  }
}
