package com.offline.music.playermp3.ui.fragmnt.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.offline.music.playermp3.api.RequestListener;
import com.offline.music.playermp3.javabean.response.ResponseCategoryList;
import com.offline.music.playermp3.network.JsonHelper;
import com.offline.music.playermp3.network.RetrofitManager;

import org.json.JSONObject;

import okhttp3.ResponseBody;

public class VMCategoryList extends ViewModel {
    private MutableLiveData<ResponseCategoryList> _data = new MutableLiveData<>();
    public LiveData<ResponseCategoryList> data = _data;


    public void getList(String browseId) {

        RetrofitManager.getInstance().getCategoryList(browseId, new RequestListener<ResponseBody>() {
            @Override
            public void onFail(String errorMsg) {
                _data.setValue(null);
            }

            @Override
            public void onSuccess(JSONObject data) {
                if (data != null) {
                    ResponseCategoryList responseCategoryList = JsonHelper.ResolveCategoryList(data,browseId);
                    _data.setValue(responseCategoryList);
                }
            }
        });
    }
}
