package com.yidian.shenghuoquan.border.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.yidian.bcommon.mvvm.BaseViewModel
import com.yidian.shenghuoquan.border.http.OrderRemoteDataSource
import com.yidian.shenghuoquan.border.http.callback.IApplyRefundCallback

/**
 * 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"))
  }

  /**
   * 跳转活动详情页
   */
  fun gotoActivityDetail() {
    // TODO: 2021/8/24 跳转H5活动详情
  }
}
