package com.tofly.latte_core.net;

import com.tofly.latte_core.config.ConfigKeys;
import com.tofly.latte_core.config.Latte;
import com.tofly.latte_core.net.base.NetWorkApi;

import com.tofly.latte_core.net.interceptor.CommonRequestInterceptor;
import com.tofly.latte_core.net.interceptor.LogInterceptor;


import okhttp3.Interceptor;
import okhttp3.OkHttpClient;

/**
 * 单个域名实现类  支持多域名  其他域名继承NetWorkApi即可
 */
public class LatteNetWorkApi extends NetWorkApi {

    private LatteNetWorkApi(String base_url) {
        super(base_url);
    }

    @Override
    public Interceptor getInterceptor() {
        return new LogInterceptor();
    }

    @Override
    public Interceptor getRequestInterceptor() {
        return new CommonRequestInterceptor();
    }

    //静态内部类创建LatteNetWorkApi实例
    private static class Holder {
        private static final LatteNetWorkApi LATTE_NET_WORK_API = new
                LatteNetWorkApi(Latte.getConfiguration(ConfigKeys.API_HOST.name()));
    }

    //获取LatteNetWorkApi 实例
    private static LatteNetWorkApi getInstance() {
        return Holder.LATTE_NET_WORK_API;
    }

    public static <T> T getApiService(Class<T> service) {
        return getInstance().getRetrofitApi(service);
    }

    @Override
    public void setOkHttp(OkHttpClient.Builder builder) {

    }
}
