"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.lowerNamingFunction = exports.upperNamingFunction = void 0;
exports.requiredOrOptional = requiredOrOptional;
const Naming_js_1 = require("../../Naming.js");
const Strings_js_1 = require("../../support/Strings.js");
const index_js_1 = require("../../Type/index.js");
const TypeUtils_js_1 = require("../../Type/TypeUtils.js");
const legalizeName = (0, Strings_js_1.legalizeCharacters)((cp) => (0, Strings_js_1.isAscii)(cp) && (0, Strings_js_1.isLetterOrUnderscoreOrDigit)(cp));
function elmNameStyle(original, upper) {
    const words = (0, Strings_js_1.splitIntoWords)(original);
    return (0, Strings_js_1.combineWords)(words, legalizeName, upper ? Strings_js_1.firstUpperWordStyle : Strings_js_1.allLowerWordStyle, Strings_js_1.firstUpperWordStyle, upper ? Strings_js_1.allUpperWordStyle : Strings_js_1.allLowerWordStyle, Strings_js_1.allUpperWordStyle, "", Strings_js_1.isLetterOrUnderscore);
}
exports.upperNamingFunction = (0, Naming_js_1.funPrefixNamer)("upper", (n) => elmNameStyle(n, true));
exports.lowerNamingFunction = (0, Naming_js_1.funPrefixNamer)("lower", (n) => elmNameStyle(n, false));
function requiredOrOptional(p) {
    function optional(fallback) {
        return { reqOrOpt: "Jpipe.optional", fallback };
    }
    const t = p.type;
    if (p.isOptional ||
        (t instanceof index_js_1.UnionType && (0, TypeUtils_js_1.nullableFromUnion)(t) !== null)) {
        return optional(" Nothing");
    }
    if (t.kind === "null") {
        return optional(" ()");
    }
    return { reqOrOpt: "Jpipe.required", fallback: "" };
}
