package com.mints.goodmoney.mvp.presenters;

import com.google.gson.JsonObject;
import com.mints.goodmoney.manager.AppHttpManager;
import com.mints.goodmoney.mvp.model.BaseResponse;
import com.mints.goodmoney.mvp.model.UserTaskMsgBean;
import com.mints.goodmoney.mvp.views.AwardView;
import com.mints.library.net.neterror.BaseSubscriber;
import com.mints.library.net.neterror.Throwable;

import java.util.HashMap;

public class AwardPresenter extends BasePresenter<AwardView> {

    public void getCoinMsg() {
        AppHttpManager.getInstance(loanApplication)
                .call(loanService.getCoinMsg(),
                        new BaseSubscriber<BaseResponse<JsonObject>>() {
                            @Override
                            public void onCompleted() {
                                if (isLinkView()) return;

                                view.hideLoading();
                            }

                            @Override
                            public void onError(Throwable e) {
                                if (isLinkView()) return;

                                view.hideLoading();
                                view.showToast(e.getMessage());
                            }

                            @Override
                            public void onNext(BaseResponse<JsonObject> baseResponse) {
                                if (isLinkView()) return;

                                int code = baseResponse.getStatus();
                                String message = baseResponse.getMessage();
                                switch (code) {
                                    case 200://成功
                                        JsonObject data = baseResponse.getData();
                                        if(data!=null){
                                            view.getUserTaskMsgSuc(data.get("coin").getAsInt());
                                        }
                                        break;
                                    default:
                                        view.showToast(message);
                                        break;
                                }
                            }
                        });
    }

    public void reportAddCoinMsg(HashMap<String, Object> vo) {
        AppHttpManager.getInstance(loanApplication)
                .call(loanService.reportAddCoinMsg(vo),
                        new BaseSubscriber<BaseResponse<Object>>() {
                            @Override
                            public void onCompleted() {
                                if (isLinkView()) return;
                            }

                            @Override
                            public void onError(Throwable e) {
                                if (isLinkView()) return;
                            }

                            @Override
                            public void onNext(BaseResponse<Object> baseResponse) {
                                if (isLinkView()) return;
                            }
                        });
    }
}
