package com.rc.httpcore.client;

import android.net.Uri;
import android.util.Log;

import com.blankj.utilcode.util.LogUtils;
import com.rc.httpcore.HttpConfig;
import com.rc.httpcore.OkHttpUtils;

import java.io.IOException;

import okhttp3.Response;

public final class HttpTool {

    public static String checkUrl(String url) {
        try {
            String uriStr = url;
            if (!url.matches("https?://.*") && !url.matches("http?://.*")) {
                uriStr = Uri.parse(HttpConfig.Companion.getAPI_BASE_URL() + url).toString();
            }
            return uriStr;
        } catch (Exception e) {
            LogUtils.e(Log.getStackTraceString(e));
            return url;
        }
    }

    /**
     * 获取柜子信息
     */
    public static Response getCabinetList(String labId) throws IOException {
        return OkHttpUtils.getSync(HttpConfig.Companion.getAPI_BASE_URL() + "chemical/aio/getCabinetList?subId=" + labId);
    }

    /**
     * 查询化学品
     */
    public static Response searchchemical(String searchValue, String chemicalLevel) throws IOException {
        return OkHttpUtils.getSync(HttpConfig.Companion.getAPI_BASE_URL() + "chemical/aio/searchChemica?searchValue=" + searchValue + "&chemicalLevel=" + chemicalLevel);
    }

}
