package com.app.simplitend.apputils;

import com.app.simplitend.BuildConfig;

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

public abstract class RetrofitHelper {

    // urls

    // Testing BASE URL
//    private static final String BASE_URL = "https://simplitend.betadelivery.com/";

    // Staging BASE URL
    private static final String BASE_URL = "https://simplitendapp.betadelivery.com/";

    public static final String IMAGE_BASE_URL = BASE_URL + "storage/upload/";

    public static final String CREATE_CONTACT = "api/contact-create";

    public static final String UPDATE_CONTACT = "api/patient-contact-update/";

    // util functions
    private static Retrofit retrofit;

    public static synchronized Retrofit getRetrofit(){
        if (retrofit == null){

            OkHttpClient.Builder builder = new OkHttpClient.Builder()
                    .addInterceptor(chain -> {
                        Request request = chain.request().newBuilder()
                                .addHeader("Accept", "*/*")
                                .addHeader("Accept-Encoding", "gzip, deflate, br")
                                .addHeader("Connection", "keep-alive")
                                .addHeader("Content-Type", "multipart/form-data")
                                .build();
                        return chain.proceed(request);
                    });

            if (BuildConfig.DEBUG){
                HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
                interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                builder.addInterceptor(interceptor);
            }

            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(builder.build())
                    .build();
        }

        return retrofit;
    }

}