package com.cooleshow.teacher.presenter.main;

import com.cooleshow.base.constanst.Constants;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.CountOfUnreadBean;
import com.cooleshow.teacher.bean.HelpCenterContentBean;
import com.cooleshow.teacher.bean.HomeCountBean;
import com.cooleshow.teacher.bean.HomeLiveAndVideoBean;
import com.cooleshow.teacher.bean.HomeMenuBean;
import com.cooleshow.teacher.bean.TeacherUserInfo;
import com.cooleshow.teacher.contract.HomeContract;
import com.cooleshow.usercenter.bean.UserInfo;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Author by pq, Date on 2022/4/20.
 */
public class HomePresenter extends BasePresenter<HomeContract.HomeView> implements HomeContract.Presenter {

    /**
     * 查询UserInfo
     *
     * @param
     */
    public void getUserInfo() {
        addSubscribe(create(APIService.class).getUserInfo(), new BaseObserver<UserInfo>(getView()) {
            @Override
            protected void onSuccess(UserInfo data) {
//                if (getView() != null) {
//                    getView().getUserInfoSuccess(data);
//                }
            }
        });
    }

    public void getTeacherUserInfo() {
        addSubscribe(create(APIService.class).getTeacherUserInfo(), new BaseObserver<TeacherUserInfo>(getView()) {
            @Override
            protected void onSuccess(TeacherUserInfo data) {
//                if (getView() != null) {
//                    getView().getTeacherInfoSuccess(data);
//                }
            }
        });
    }


    public void getHomeCount() {
        addSubscribe(create(APIService.class).getHomeCount(), new BaseObserver<HomeCountBean>(getView()) {
            @Override
            protected void onSuccess(HomeCountBean data) {
                if (getView() != null) {
                    getView().getHomeCountSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }

    public void helpCenterContentList() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("catalogIds", "2");
            jsonObject.putOpt("catalogType", "TEACHER");
            jsonObject.putOpt("page", 1);
            jsonObject.putOpt("status", 1);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).helpCenterContentList(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HelpCenterContentBean>(getView()) {
            @Override
            protected void onSuccess(HelpCenterContentBean data) {
                if (getView() != null) {
                    getView().helpCenterContentListSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }


    public void queryCountOfUnread() {
        addSubscribe(create(APIService.class).queryCountOfUnread(), new BaseObserver<List<CountOfUnreadBean>>(getView()) {
            @Override
            protected void onSuccess(List<CountOfUnreadBean> data) {
                if (getView() != null) {
                    getView().queryCountOfUnreadSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }

    public void queryLiveAndVideo() {
        addSubscribe(create(APIService.class).queryLiveAndVideo(), new BaseObserver<HomeLiveAndVideoBean>(getView()) {
            @Override
            protected void onSuccess(HomeLiveAndVideoBean data) {
                if (getView() != null) {
                    getView().queryLiveAndVideoSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }

    /**
     * 获取App首页入口信息
     */
    public void appHome() {
        getView().showLoading();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("platform", "android");
            jsonObject.putOpt("version", "1");
            jsonObject.putOpt("clientType", "TEACHER");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).appHome(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HomeMenuBean>(getView()) {
            @Override
            protected void onSuccess(HomeMenuBean data) {
                if (null != getView()) {
                    getView().appHomeSuccess(data);
                }
            }
        });
    }
}
