package com.cheng.blzb.ui.fragment.search

import androidx.lifecycle.MutableLiveData
import com.cheng.blzb.net.ApiFactory
import com.example.base.extensions.toast
import com.example.base.utils.L
import com.example.base.viewmodel.BaseViewModel

class SearchViewModel: BaseViewModel() {
    val recommendLiveData = MutableLiveData<List<String>>()

    fun getHotKeywordList(query: String) {
        showDialog()
        launchOnUiTryCatch({
            val params = mutableMapOf<String, String>()
            params["query"] = query
            params["size"] = "12"
            val response = ApiFactory.apiService.getHotKeywords(params)
            if (response.status) {
                recommendLiveData.postValue(response.data)
            } else toast(response.message, true)
            dismissDialog()
        }, {
            dismissDialog()
            setError(it)
            L.d(it)
        })
    }
}