package com.yidianling.home.model

import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.yidianling.home.http.HomeHttp
import com.yidianling.home.model.bean.*
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述:
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/13
 */
class HomeModelImpl {

    companion object {
        /**
         * 首页咨询请求
         */
        fun consultRequest(category: String): Observable<HomeConsultBean> {
            return HomeHttp.getInstance().getConsultData(category).compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { HomeConsultBean(true) }
        }

        /**
         * 首页问答 - 点赞
         */
        fun askZan(id: String): Observable<AskResultBean> {
            return HomeHttp.getInstance().askZan(id).compose(RxUtils.resultData())
        }

        /**
         * 首页问答 - 关注
         */
        fun askFocus(id: String): Observable<AskResultBean> {
            return HomeHttp.getInstance().askFocus(id).compose(RxUtils.resultData())
        }

        /**
         * 首页电台请求
         */
        fun fmRequest(): Observable<HomeFMBean> {
            return HomeHttp.getInstance().getFMData().compose(RxUtils.resultJavaData())
                .onErrorReturn { HomeFMBean(true) }
        }

        /**
         * 首页课程请求
         */
        fun courseRequest(): Observable<HomeCourseBean> {
            return HomeHttp.getInstance().getCourseData().compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { HomeCourseBean(true) }
        }

        /**
         * 首页测试题请求
         */
        fun testRequest(): Observable<BaseAPIResponse<MutableList<HomeTestItemBean>>> {
            return HomeHttp.getInstance().getTestData()
        }

        /**
         * 首页倾听请求
         */
        fun confideRequest(goodType: String): Observable<HomeConfideBean> {
            return HomeHttp.getInstance().getConfideData(goodType).compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { HomeConfideBean(true) }
        }

        /**
         * 首页问答请求
         */
        fun askRequest(): Observable<HomeAskBean> {
            return HomeHttp.getInstance().getAskData().compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { HomeAskBean(true) }
        }

        /**
         * 首页文章请求
         */
        fun articleRequest(): Observable<HomeArticleBean> {
            return HomeHttp.getInstance().getArticleData().compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { HomeArticleBean(true) }
        }

        /**
         * 首页头部 分类&Banner请求
         */
        fun headerRequest(): Observable<HomeHeaderBean> {
            return HomeHttp.getInstance().newHomeHeaderRequest().compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { HomeHeaderBean(true) }
        }

        /**
         * 首页冥想请求
         */
        fun museRequest(): Observable<MuseModuleBean> {
            return HomeHttp.getInstance().newMuseRequest().compose(RxUtils.resultJavaData())
                .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
                .onErrorReturn { MuseModuleBean(true) }
        }
    }


}