package com.hc.viewmodel;

import android.support.annotation.NonNull;

import com.hc.request.core.IHttpCallback;
import com.orhanobut.logger.Logger;

public class ViewModelHttpCallback<T> implements IHttpCallback<T> {

    private BaseViewModel viewModel;

    ViewModelHttpCallback(BaseViewModel viewModel) {
        this.viewModel = viewModel;
    }

    @Override
    public void onStart(int what) {
        viewModel.getSingleBooleanEvent().setValue(true);
    }

    @Override
    public void onSuccess(int what, @NonNull T data) {
        Logger.d(data);
    }

    @Override
    public void onFail(int what, String msg) {
        Logger.e(msg);
        viewModel.getInvalidDataEvent().setValue(true);
    }

    @Override
    public void onError(int what, Throwable e) {
        Logger.e(e.getMessage());
        viewModel.getInvalidDataEvent().setValue(true);
    }

    @Override
    public void onFinish(int what) {
        viewModel.getSingleBooleanEvent().setValue(false);
    }
}
