package com.yidian.shenghuoquan.buserorder.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.yidian.bcommon.constant.XBirdPageConstants
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.mvvm.BaseViewModel
import com.yidian.shenghuoquan.buserorder.http.OrderRemoteDataSource
import com.yidian.shenghuoquan.buserorder.http.callback.IApplyRefundCallback
import com.yidian.xpage.XPageManager

/**
 * author: yinjiacheng
 * date: 2021/8/23 13:54
 * description: 订单商品信息
 */
class OrderCommodityInfoViewModel : BaseViewModel() {

  private val _applyRefundResult = MutableLiveData<Boolean>()
  val applyRefundResult: LiveData<Boolean> = _applyRefundResult

  private val _applyRefund = MutableLiveData<String>()
  val applyRefund: LiveData<String> = _applyRefund

  private val _contractSeller = MutableLiveData<String>()
  val contractSeller: LiveData<String> = _contractSeller

  /**
   * 申请退款
   * @param orderId 订单id
   */
  fun applyRefund(orderId: String) {
    _applyRefund.value = orderId
  }

  /**
   * 联系卖家
   * @param phone 电话号码
   */
  fun contractSeller(phone: String) {
    _contractSeller.value = phone
  }

  /**
   * 请求申请退款接口
   * @param orderId 订单id
   */
  fun requestApplyRefund(orderId: String) {
    OrderRemoteDataSource.applyRefund(object : IApplyRefundCallback {
      override fun applyRefundSuccess() {
        _applyRefundResult.value = true
      }

      override fun applyRefundFailure(message: String?) {
        _applyRefundResult.value = false
      }

    }, hashMapOf("order_id" to orderId, "business_from" to "2"))
  }

  /**
   * 跳转活动详情页
   * @param marketingId 活动id
   */
  fun gotoMarketingDetail(marketingId: Long) {
    val pageUrl = XBirdPageConstants.FIGHT_ORDER_EVENT_DETAILS + "?marketing_id=${marketingId}"
    XPageManager.push(XRouterPathConstants.COMMON_WEB_VIEW_ACTIVITY, hashMapOf(Pair(XBirdPageConstants.PAGE_URL, pageUrl)))
  }
}
