package com.yidianling.ydlcommon.custom.ui.couponhint.http

import com.yidianling.ydlcommon.custom.http.BaseAPIResponse
import com.yidianling.ydlcommon.custom.http.RxUtils
import com.yidianling.ydlcommon.custom.http.YdlRetrofitUtils
import com.yidianling.ydlcommon.custom.ui.couponhint.CouponHintParam
import com.yidianling.ydlcommon.custom.ui.couponhint.CouponHintResponseBean
import io.reactivex.Observable

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述:
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/12/27
 */
class CouponHintHttpImpl private constructor(): ICouponHintHttp {

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

    object Holder {
        val INSTANCE = CouponHintHttpImpl()
    }

    private val couponHintApi: CouponHintApi by lazy {
        com.yidianling.ydlcommon.custom.http.YdlRetrofitUtils.getRxRetrofit().newBuilder().baseUrl(com.yidianling.ydlcommon.custom.http.YdlRetrofitUtils.SERVER_API_JAVA_URL).build().create(
            CouponHintApi::class.java)
    }

    override fun getCouponHint(param: CouponHintParam): Observable<com.yidianling.ydlcommon.custom.http.BaseAPIResponse<CouponHintResponseBean>> {
        return RxUtils.mapObservable(param)
                .flatMap {
                    couponHintApi.getCouponHint()
                }
    }
}