package com.common.commonlibtest.manager

import com.common.commonlib.net.BaseObserve
import com.common.commonlib.net.callback.RequestCallBack
import com.common.commonlibtest.bean.CollectionResponse
import io.reactivex.rxjava3.core.Observable
import okhttp3.Interceptor
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Path

class CollectionLoader : BaseObserve<CollectionLoader.CollectionApi> {
    var myApi: CollectionApi? = null
    var myInterceptorApi : CollectionApi? = null

    constructor() : super(CollectionApi::class.java)
    constructor(interceptors: List<Interceptor>) : super(CollectionApi::class.java, interceptors)

    init {
        myApi = initService(CollectionApi::class.java)
    }

    fun init(interceptors: List<Interceptor>) {
        myApi = initService(CollectionApi::class.java)
        myInterceptorApi = initService(CollectionApi::class.java, interceptors)
    }

    fun getCollections(pageName: Int, callBack: RequestCallBack<CollectionResponse>) {
        observe(api.getCollections(pageName), callBack)
    }

    interface CollectionApi {
        @Headers("baseurl:debug1")
        @GET("/lg/collect/list/{pageNum}/json")
        fun getCollections(@Path("pageNum") pageNum: Int): Observable<CollectionResponse>
    }
}