package com.yidianling.course.coursePlay.http

import com.yidianling.course.coursePlay.common.net.NetApiStore
import com.yidianling.course.coursePlay.moudle.CourseListDataBean
import com.yidianling.ydlcommon.http.BaseAPIResponse
import com.yidianling.ydlcommon.http.RxUtils
import com.yidianling.ydlcommon.http.YdlRetrofitUtils
import io.reactivex.Observable

/**
 * @author yuanWai
 * @描述:课程列表页接口实现类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/12/12
 */
class CourseListHttpImpl : ICourseListHttp{

    companion object {
        fun getInstance(): CourseListHttpImpl {
            return Holder.INSTANCE
        }
    }

    object Holder {
        val INSTANCE = CourseListHttpImpl()
    }

    private val netApiStore: NetApiStore by lazy {
        YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(YdlRetrofitUtils.SERVER_API_JAVA_URL).build().create(NetApiStore::class.java)
    }

    override fun getCourseList(params: String): Observable<BaseAPIResponse<CourseListDataBean>> {
        return RxUtils.mapObservable(CourseListParams(""))
                .flatMap {netApiStore.getCourseList(YdlRetrofitUtils.SERVER_API_JAVA_URL + "auth/course/getList?" + params)
                }
    }
}