package com.cooleshow.student.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.student.api.APIService;
import com.cooleshow.student.bean.AppHomeBean;
import com.cooleshow.student.bean.CountOfUnreadBean;
import com.cooleshow.student.bean.HelpCenterContentBean;
import com.cooleshow.student.bean.HomeLiveAndVideoBean;
import com.cooleshow.student.bean.HomeStyleBean;
import com.cooleshow.student.bean.HotAlbumBean;
import com.cooleshow.student.bean.StudentUserInfo;
import com.cooleshow.student.contract.HomeContract;

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

import java.util.List;

/**
 * 创建日期：2022/5/26 10:09
 *
 * @author Ryan
 * 类说明：
 */
public class HomePresenter extends BasePresenter<HomeContract.HomeView> implements HomeContract.Presenter {
    public void appHome() {
        getView().showLoading();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("platform", "android");
            jsonObject.putOpt("version", "1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).appHome(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<AppHomeBean>(getView()) {
            @Override
            protected void onSuccess(AppHomeBean data) {
                if (null != getView()) {
                    getView().appHomeSuccess(data);
                }
            }

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

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

            }
        });
    }


    public void userAccountPage() {

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("platform", "android");
            jsonObject.putOpt("version", "1");
            jsonObject.putOpt("page", 1);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).hotAlbumList(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HotAlbumBean>(getView()) {
            @Override
            protected void onSuccess(HotAlbumBean data) {
                if (getView() != null) {
                    getView().hotAlbumListSuccess(data);
                }
            }

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

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

            }
        });
    }

    public void queryLiveAndVideo() {
        addSubscribe(create(APIService.class).queryLiveAndVideo("android", "1"), 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);

            }
        });
    }


    public void helpCenterContentList() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("catalogIds", "2");
            jsonObject.putOpt("catalogType", "STUDENT");
            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 getStylePage() {

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.putOpt("platform", "android");
            jsonObject.putOpt("version", "1");
            jsonObject.putOpt("page", 1);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).getStylePage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HomeStyleBean>(getView()) {
            @Override
            protected void onSuccess(HomeStyleBean data) {
                if (getView() != null) {
                    getView().getStylePageSuccess(data);
                }
            }

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

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

            }
        });
    }

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




    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);

            }
        });
    }
}
