package com.yidian.yac.newscontent.http

import android.util.Log
import com.yidian.common.http.HttpCommonParamsUtils
import com.yidian.common.http.HttpResult
import com.yidian.common.http.HttpResultSubscriber
import com.yidian.common.http.TransformUtil
import com.yidian.http.ServiceFactory
import com.yidian.yac.newscontent.http.httpbean.AppInitBean
import com.yidian.yac.newscontent.http.httpbean.IUploadFileCallback
import okhttp3.MultipartBody

class ApiService {
    companion object {

        fun appInit(requestParams: AppInitBean.Request){
            ServiceFactory.getInstance().createService(CommonService::class.java)
                .appInit(HttpCommonParamsUtils.getParamsMap(),requestParams)
                .compose(TransformUtil.defaultSchedulers())
                .subscribe(object : HttpResultSubscriber<String?>() {
                    override fun onSuccess(result: HttpResult<String?>?) {
                        Log.d("yue.huang","onSuccess"+result?.result)
                    }

                    override fun onFailer(result: HttpResult<String?>?) {
                        Log.d("yue.huang","onFailer"+result?.result)
                    }
                })
        }

        fun uploadFile(apiCallback: IUploadFileCallback, requestParams: MultipartBody.Part) {
            val paramsMap = HttpCommonParamsUtils.getParamsMap()
            ServiceFactory.getInstance().createService(CommonService::class.java)
                .uploadFile(paramsMap, requestParams)
                .compose(TransformUtil.defaultSchedulers())
                .subscribe(object : HttpResultSubscriber<Any?>() {
                    override fun onSuccess(result: HttpResult<Any?>?) {
                        apiCallback.uploadFileCallBack(result)
                    }

                    override fun onFailer(result: HttpResult<Any?>?) {
                        apiCallback.uploadFileCallBack(result)
                    }

                })
        }
    }
}
