/*
 * Copyright (c) 2020. Lemon Healthcare
 *
 *
 */

package com.lemonhc.mplus.httpRequest;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class APIClient {

    private static Retrofit retrofit = null;
    private static String apiURL = "https://4q99982zrt.apigw.ntruss.com/";
    private static Retrofit.Builder builder = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .baseUrl(apiURL);

    public static Retrofit getClient() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        retrofit = new Retrofit.Builder()
                .baseUrl(apiURL) //baseUrl은 항상 '/'로 끝나야 함.
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();

        return retrofit;
    }


    public static void updateURL (String url) {

        apiURL = url;


        builder = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(apiURL);


    }

    // 자꾸 아래와 같은 에러가 뜨면 폰의 네트워크 상태를 확인할것.
    // https://rlg1133.tistory.com/35
    // HTTP FAILED: java.net.UnknownHostException: Unable to resolve host
}