package com.yidian.shenghuoquan.buserorder.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.yidian.bcommon.mvvm.BaseViewModel
import com.yidian.shenghuoquan.buserorder.app.bean.OrderWebData
import com.yidian.shenghuoquan.buserorder.http.UserOrderListOperation
import com.yidian.shenghuoquan.buserorder.http.callback.OrderListCallBack

class OrderListViewModel : BaseViewModel(){
    companion object {
      const val NORMAL = "NORMAL"
      const val REFUND = "REFUND"
      const val PULL = "PULL"
      const val LOAD = "LOAD"
    }

    private var orderList:MutableLiveData<List<OrderWebData>> = MutableLiveData<List<OrderWebData>>()
    var _orderList:LiveData<List<OrderWebData>> = orderList
    var _listType:String = NORMAL
    var _operationType = PULL
    fun requestFreshUserOrder(param:HashMap<String, String?>) {
      _operationType = PULL
      UserOrderListOperation.userOrderList(generateRereshParma(param), orderListCallBack)
    }
  fun requestLoadMoreUserOrder(param:HashMap<String, String?>) {
    _operationType = LOAD
    UserOrderListOperation.userOrderList(generateLoadmoreParma(param), orderListCallBack)
  }
    private var orderListCallBack = object : OrderListCallBack {
      override fun onOrderListCallback(orders: List<OrderWebData>?) {
        if (orders != null) {
          orderList.value = orders!!
        }
      }
    }

  private fun generateLoadmoreParma(param:HashMap<String, String?>):HashMap<String, String?> {
    param["business_from"] = "2"
    if (_listType == REFUND) {
      param["order_status"] = "5"
    }
    param["num"] = "${_orderList.value!!.size + 10}"
    return param
  }
  private fun generateRereshParma(param:HashMap<String, String?>):HashMap<String, String?> {
    param["business_from"] = "2"
    if (_listType == REFUND) {
      param["order_status"] = "5"
    }
    param["num"] = "10"
    return param
  }
}
