package com.zswc.creativity.vmodel

import android.app.Application
import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import com.zswc.creativity.activity.RechargeActivity
import com.zswc.creativity.activity.WithdrawalActivity
import com.zswc.creativity.config.MIntentAction
import com.zswc.creativity.fragment.AccountBillFragment
import com.zswc.creativity.model.AmountCount
import com.zswc.creativity.model.User
import com.zswc.creativity.utils.net.NetEngine
import com.ysnows.base.base.BRRepository
import com.ysnows.base.base.BRViewModel
import com.ysnows.base.net.IResp
import com.ysnows.base.utils.UiSwitch

/**
 *Created by shihuiyun
 *on 2020/9/18
 */
class AccountBillVModel(application: Application) : BRViewModel<BRRepository>(application) {


    val user: MutableLiveData<User?> = MutableLiveData(User.get())
    var info: MutableLiveData<AmountCount> = MutableLiveData<AmountCount>()

    var fragment: AccountBillFragment? = null
    var status = "0"


    fun getAmountCount() {

        repository().rxPreq(NetEngine.service.amountCount())
                .doOnNext {
                    if (it.ok(false)) {
                        var bean = it.data() as AmountCount
                        if (null != bean) {
                            info.value = bean
                        }

                    }
                }
                .subscribe()
    }


    fun goWithdrawal() {//提现

        UiSwitch.bundleRes(fragment, WithdrawalActivity::class.java, Bundle().apply {
            putString("money", info.value!!.can_use)
        }, MIntentAction.REQUEST_CODE_ONE)

    }

    fun toBillDetails() {//账单明细

       // UiSwitch.single(repository().context, BillDetailsActivity::class.java)

    }

    fun toRecharge() {//去充值

        UiSwitch.singleRes(fragment, RechargeActivity::class.java, MIntentAction.REQUEST_CODE_ONE)
    }

    override fun apiFunc(): suspend () -> IResp<*> {
        return { NetEngine.service.amountList( status, "","","",repository().page) }
    }
}
