package com.mints.goodmoney.mvp.presenters;

import com.google.gson.JsonObject;
import com.mints.goodmoney.manager.AppHttpManager;
import com.mints.goodmoney.manager.UserManager;
import com.mints.goodmoney.mvp.model.BaseResponse;
import com.mints.goodmoney.mvp.model.MyInfo;
import com.mints.goodmoney.mvp.model.UserBean;
import com.mints.goodmoney.mvp.views.GameView;
import com.mints.goodmoney.utils.DeviceUuidFactory;
import com.mints.library.net.neterror.BaseSubscriber;
import com.mints.library.net.neterror.Throwable;

import java.util.HashMap;

public class GamePresenter extends BasePresenter<GameView> {

    /**
     * 猎豹游戏上传信息
     */
    public void gameAdd(String url, String eventType, HashMap<String, Object> vo) {
        AppHttpManager.getInstance(loanApplication)
                .call(loanService.gameAdd(url, vo),
                        new BaseSubscriber<BaseResponse<Object>>() {
                            @Override
                            public void onCompleted() {
                                if (isLinkView()) return;

                                view.hideLoading();
                            }

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

                                view.hideLoading();
                            }

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

                                int code = baseResponse.getStatus();
                                switch (code) {
                                    case 200://成功
                                        view.gameAddSuc(eventType, baseResponse.getData());
                                        break;
                                }
                            }
                        });
    }


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

                                view.hideLoading();
                            }

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

                                view.hideLoading();
                            }

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

                                int code = baseResponse.getStatus();
                                JsonObject data = baseResponse.getData();
                                switch (code) {
                                    case 200://成功
                                        if (data != null) {
                                            JsonObject gameMsg = data.getAsJsonObject("msg");
                                            view.gameInfo(gameMsg.get("needSecods").getAsInt(), gameMsg.get("coin").getAsInt(), gameMsg.get("completeSeconds").getAsInt());
                                        }
                                        break;
                                }
                            }
                        });
    }
}
