package com.anythink.reactnative.utils;

import android.util.Log;

import com.thinkup.core.api.AdError;

/**
* Bridge layer log.
* TAG fixed `ATRNBridge`; double-opened with SDK log during init (see ATInitManager).
 */
public class MsgTools {
    public static final String TAG = "ATRNBridge";
    public static boolean isDebug = false;

    public static void printMsg(String msg) {
        if (isDebug) {
            Log.i(TAG, msg != null ? msg : "null");
        }
    }

    /** Aligned with iOS ATLog: AdType:ClassName::methodName:params */
    public static void printCallback(String adType, String className, String methodName, String params) {
        if (!isDebug) {
            return;
        }
        String msg = adType + ":" + className + "::" + methodName;
        if (params != null && params.length() > 0) {
            msg += ":" + params;
        }
        printMsg(msg);
    }

    /** Ad source callback (aligned with iOS ADSource--AD--Start--Class::method). */
    public static void printAdSource(String phase, String className, String methodName, String params) {
        if (!isDebug) {
            return;
        }
        String msg = phase + "--" + className + "::" + methodName;
        if (params != null && params.length() > 0) {
            msg += ":" + params;
        }
        printMsg(msg);
    }

    public static String adSourceParams(String placementId, Object adInfo) {
        return "placementId=" + placementId + "--adInfo=" + adInfo;
    }

    public static String adSourceErrorParams(String placementId, Object adInfo, AdError adError) {
        String err = adError != null ? adError.getFullErrorInfo() : "";
        return "placementId=" + placementId + "--adInfo=" + adInfo + "--error=" + err;
    }

    public static void setLogDebug(boolean debug) {
        isDebug = debug;
    }
}
