package com.casic.dcms.mvp.presenter.impl;

import com.casic.dcms.bean.UserBean;
import com.casic.dcms.listener.OnGetUserListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.UserDataModelImpl;
import com.casic.dcms.mvp.presenter.IUserDataPresenter;
import com.casic.dcms.mvp.view.IUserDataView;

public class UserDataPresenterImpl extends BasePresenter implements IUserDataPresenter, OnGetUserListener {

    private final IUserDataView view;
    private final UserDataModelImpl actionModel;

    public UserDataPresenterImpl(IUserDataView userDataView) {
        this.view = userDataView;
        actionModel = new UserDataModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest() {
        addSubscription(actionModel.sendUserDataRequest());
    }

    @Override
    public void disposeRetrofitRequest() {
        unSubscription();
    }

    @Override
    public void onSuccess(UserBean userBean) {
        view.obtainUserData(userBean);
    }

    @Override
    public void onFailure(Throwable throwable) {
        view.obtainDataFail();
    }
}
