import { funPrefixNamer } from "../../Naming.js";
import { allLowerWordStyle, allUpperWordStyle, combineWords, firstUpperWordStyle, isDigit, isLetterOrUnderscore, isNumeric, legalizeCharacters, splitIntoWords, } from "../../support/Strings.js";
import { invalidSymbols, keywords } from "./constants.js";
/**
 * Check if given parameter name should be wrapped in a backtick
 * @param paramName
 */
export const shouldAddBacktick = (paramName) => {
    return (keywords.some((s) => paramName === s) ||
        invalidSymbols.some((s) => paramName.includes(s)) ||
        !isNaN(+Number.parseFloat(paramName)) ||
        !isNaN(Number.parseInt(paramName.charAt(0))));
};
export const wrapOption = (s, optional) => {
    if (optional) {
        return "Option[" + s + "]";
    }
    else {
        return s;
    }
};
function isPartCharacter(codePoint) {
    return isLetterOrUnderscore(codePoint) || isNumeric(codePoint);
}
function isStartCharacter(codePoint) {
    return isPartCharacter(codePoint) && !isDigit(codePoint);
}
const legalizeName = legalizeCharacters(isPartCharacter);
export function scalaNameStyle(isUpper, original) {
    const words = splitIntoWords(original);
    return combineWords(words, legalizeName, isUpper ? firstUpperWordStyle : allLowerWordStyle, firstUpperWordStyle, isUpper ? allUpperWordStyle : allLowerWordStyle, allUpperWordStyle, "", isStartCharacter);
}
/* function unicodeEscape(codePoint: number): string {
    return "\\u" + intToHex(codePoint, 4);
} */
// const _stringEscape = utf32ConcatMap(escapeNonPrintableMapper(isPrintable, unicodeEscape));
/* function stringEscape(s: string): string {
    // "$this" is a template string in Kotlin so we have to escape $
    return _stringEscape(s).replace(/\$/g, "\\$");
} */
export const upperNamingFunction = funPrefixNamer("upper", (s) => scalaNameStyle(true, s));
export const lowerNamingFunction = funPrefixNamer("lower", (s) => scalaNameStyle(false, s));
