import store from "@/store";
import { getQuerystringParameter } from "@/helpers/querystring-helper";
import { queryStrings } from "@/constants/query-strings";
import { storeActions } from "@/constants/store-actions";

export function debugLog(message, data, forceLog = false) {
    checkLogParam();

    if (store?.getters?.applicationUser?.loggingOption || forceLog) {
        data = data ?? "";
        const outData = typeof data === "object" ? JSON.stringify(data) : data;

        console.log(`${new Date()} ${message} ${outData}`);
    }
}

export function checkLogParam() {
    const logQueryString = getQuerystringParameter(queryStrings.LOG);

    if (logQueryString) {
        store?.dispatch(storeActions?.SAVE_LOGGING_OPTION, logQueryString);
    }
}
