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

import com.yidianling.ydlcommon.custom.http.RxUtils
import com.yidianling.ydlcommon.custom.ui.confideredpacket.RedListParam
import io.reactivex.Observable

/**
 * @author yuanwai
 * @描述:倾诉红包接口实现类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/11/28
 */
class ConfideRedPacketHttpImpl private constructor() :
    IConfideRedPacketHttp {


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

    object Holder {
        val INSTANCE = ConfideRedPacketHttpImpl()
    }

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

    override fun getCouponMax(param: RedListParam): Observable<com.yidianling.ydlcommon.custom.http.BaseAPIResponse<String>> {
        val sb = StringBuffer()
        sb.append("serviceType").append("=").append(param.serviceType).append("&")
        val confideParam = sb.toString() + com.yidianling.ydlcommon.custom.http.YdlRetrofitUtils.getCommonParam()

        return RxUtils.mapObservable(param)
                .flatMap {
                    //                    confideHomeApi.getCouponMax(BuildConfig.SERVER_JAVA_API_URL + "auth/coupon/max?"+confideParam)
                    confideHomeApi.getCouponMax(com.yidianling.ydlcommon.custom.http.YdlRetrofitUtils.SERVER_API_JAVA_URL + "auth/coupon/max?" + confideParam)
                }
    }
}