package com.lukouguoji.aerologic.page.flight.query.details

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.FlightBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.launchLoadingCollect

class FlightQueryDetailsViewModel : BaseViewModel() {

    var id = ""

    var dataBean = MutableLiveData<FlightBean>()

    fun initOnCreated(intent: Intent) {
        id = intent.getStringExtra(Constant.Key.ID) ?: ""

        getData()
    }

    private fun getData() {
        launchLoadingCollect({
            NetApply.api.getFlightDetails(id)
        }) {
            onSuccess = {
                it.data?.let { data ->
                    dataBean.value = data
                }
            }
        }
    }
}