package com.quyunshuo.module.home.fragment.fragment.pay

import android.content.Context
import androidx.fragment.app.viewModels
import com.elvishew.xlog.XLog
import com.quyunshuo.androidbaseframemvvm.base.addressenum.PayEnum
import com.quyunshuo.androidbaseframemvvm.base.utils.RegisterEventBus
import com.quyunshuo.androidbaseframemvvm.common.constant.Heartbeat
import com.quyunshuo.androidbaseframemvvm.common.constant.MqName
import com.quyunshuo.androidbaseframemvvm.common.constant.PayName
import com.quyunshuo.androidbaseframemvvm.common.constant.event.ApiMessageEvent
import com.quyunshuo.androidbaseframemvvm.common.ui.BaseFragment
import com.quyunshuo.androidbaseframemvvm.common.util.UiUtil
import com.quyunshuo.androidbaseframemvvm.common.util.XLogUtil
import com.quyunshuo.module.home.R
import com.quyunshuo.module.home.bean.ColseFragment
import com.quyunshuo.module.home.databinding.HomeFragmentBillCoinBinding
import com.quyunshuo.module.home.databinding.HomeFragmentFreeMakeBinding
import com.quyunshuo.module.home.dialog.PayChooseDialogFragment
import com.quyunshuo.module.home.fragment.vm.BuyFragmentVM
import com.quyunshuo.module.home.utils.OrderNumberGenerator
import dagger.hilt.android.AndroidEntryPoint
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.math.BigDecimal

/**
 *免费制作 对话框
 *
 * @author Qu Yunshuo
 * @since 2021/8/1 11:46 下午
 */
@RegisterEventBus
@AndroidEntryPoint
class FreeMakeFragment : BaseFragment<HomeFragmentFreeMakeBinding, BuyFragmentVM>() {

    override val mViewModel: BuyFragmentVM by viewModels()
    override fun createVB() = HomeFragmentFreeMakeBinding.inflate(layoutInflater)
    var sumPrice: BigDecimal? = null

    override fun HomeFragmentFreeMakeBinding.initView() {
        sumPrice = BigDecimal(arguments?.getDouble("PRICE", 0.0)!!)
        XLogUtil.d("price:" + sumPrice + Heartbeat.acceptBill)
        tvStartMake.setOnClickListener {
            XLogUtil.d("开始免费制作")
            //传递支付方式。
            EventBus.getDefault().post(
                ApiMessageEvent(
                    MqName.PAY_SUCCESS, PaySuccessBean(
                        UiUtil.getStringRes(
                            R.string.base_free_pay
                        ), OrderNumberGenerator.generateOrderNumber()
                    )
                )
            )
            //   EventBus.getDefault().post(ColseFragment("PayChooseDialogFragment",""))

        }
    }

    override fun initObserve() {
    }

    override fun initRequestData() {
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    fun event(message: ApiMessageEvent) {
        when (message.name) {
            PayName.ACCEPT_BILL -> {
            }

            else -> {}
        }
    }
}