package com.yidian.shenghuoquan.buserorder.viewmodel

import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.yidian.bcommon.mvvm.BaseViewModel
import com.yidian.shenghuoquan.buserorder.R
import com.yidian.shenghuoquan.buserorder.manager.OrderStatus

/**
 * author: yinjiacheng
 * date: 2021/8/23 13:50
 * description: 订单状态
 */
class OrderStatusViewModel : BaseViewModel() {

  companion object {
    /**
     * 订单状态图标
     * @param target 目标ImageView
     * @param status 订单状态
     */
    @BindingAdapter("orderStatusImage")
    @JvmStatic
    fun setOrderStatusImage(target: ImageView, status: OrderStatus?) {
      target.setImageResource(
        when (status) {
          OrderStatus.ORDER_STATUS_PAID -> R.drawable.icon_order_status_paid
          OrderStatus.ORDER_STATUS_WAIT_REFUND -> R.drawable.icon_order_status_wait_refund
          OrderStatus.ORDER_STATUS_ON_REFUND -> R.drawable.icon_order_status_on_refund
          OrderStatus.ORDER_STATUS_REFUNDED, OrderStatus.ORDER_STATUS_PART_REFUND -> R.drawable.icon_order_status_refunded
          OrderStatus.ORDER_STATUS_REFUSE_REFUND -> R.drawable.icon_order_status_refuse_refund
          else -> R.drawable.icon_order_status_paid
        }
      )
    }

    /**
     * 订单状态描述
     * @param target 目标TextView
     * @param status 订单状态
     * @param refundAmount 订单退款金额
     */
    @BindingAdapter(value = ["orderStatusDescription", "orderRefundAmount"], requireAll = true)
    @JvmStatic
    fun setOrderStatusText(target: TextView, status: OrderStatus?, refundAmount: Double?) {
      target.text = when (status) {
        OrderStatus.ORDER_STATUS_WAIT_REFUND -> "待商家确认"
        OrderStatus.ORDER_STATUS_REFUNDED, OrderStatus.ORDER_STATUS_PART_REFUND -> "退款金额: ¥$refundAmount"
        OrderStatus.ORDER_STATUS_REFUSE_REFUND -> "如有疑问请联系卖家"
        else -> ""
      }
    }
  }
}
