package xn.hxp.http;

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

import com.blankj.utilcode.util.LogUtils;

import xn.hxp.room.bean.DeviceInfo;
import xn.hxp.room.tool.DeviceInfoTool;

public enum HttpTool {
    INSTANCE;

    private DeviceInfo deviceInfo;

    HttpTool() {
        deviceInfo = DeviceInfoTool.INSTANCE.getDeviceInfo();
    }

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