package com.qimai.android.fetch.download

import com.qimai.android.fetch.retrofit.RetrofitBuilder
import okhttp3.OkHttpClient
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Response


/**
 *   created by wangwei   ON 2019-12-31  email:wangwei_5521@163.com
 *   @version 1.1.1
 *   @Description
 **/


class DownLoaderHelper private constructor() {

    var apiService: DownloadApi

    private var retrofit = RetrofitBuilder.Builder()
        .okhttpClient(
            OkHttpClient.Builder()
                .addInterceptor(DownloadInterceptor()).build()
        )
        .build()

    init {
        apiService = retrofit.create(DownloadApi::class.java)
    }


    fun downloadFile(url: String) {
        apiService.downloadFile(url)
            .enqueue(object : retrofit2.Callback<ResponseBody> {
                override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
                }

                override fun onResponse(
                    call: Call<ResponseBody>,
                    response: Response<ResponseBody>
                ) {

                }
            })
    }

    companion object {

        val instance: DownLoaderHelper by lazy {

            DownLoaderHelper()
        }
    }
}