package com.yidianling.course.course_special_list.http

import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlcommon.data.http.BaseCommand
import com.ydl.ydlcommon.data.http.FormatText
import com.ydl.ydlcommon.utils.NetworkParamsUtils
import com.ydl.ydlnet.YDLHttpUtils
import com.yidianling.course.course_special_list.bean.CourseSpecialListBean
import io.reactivex.Observable

/**
 * @author yuanwai
 * @描述:课程专题列表接口实现类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/9/18
 */
class CourseSpecialListHttpImpl private constructor() : ICourseSpecialListHttp {

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

        fun clearCourseSpecialListApi() {
            Holder.INSTANCE.courseSpecialListApi = null
        }
    }

    object Holder {
        val INSTANCE = CourseSpecialListHttpImpl()
    }

    fun getPostList(crq: BaseCommand): List<FormatText> {
        return NetworkParamsUtils.getPostList(crq)
    }

    fun getMaps(list: List<FormatText>): Map<String, String> {
        return NetworkParamsUtils.getMaps(list)
    }

    private var courseSpecialListApi: CourseSpecialListApi? = null


    override fun courseSpecialList(param: CourseSpecialListParam): Observable<BaseAPIResponse<CourseSpecialListBean>> {
        val list = getPostList(param)
        return YDLHttpUtils.obtainApi(CourseSpecialListApi::class.java!!).courseSpecialList(getMaps(list))
    }
}