const validCustomTagInputTypes = ['mapping', 'scalar', 'sequence'];
const customTagReturnTypeAliases = {
    mapping: 'object',
    object: 'object',
    sequence: 'array',
    array: 'array',
    scalar: 'string',
    string: 'string',
    number: 'number',
    integer: 'integer',
    boolean: 'boolean',
    null: 'null',
};
export function parseCustomTag(customTagStr) {
    if (typeof customTagStr !== 'string')
        return undefined;
    const typeInfo = customTagStr.trim().split(/\s+/);
    const tag = typeInfo[0];
    if (!tag)
        return undefined;
    const rawType = (typeInfo[1] && typeInfo[1].toLowerCase()) || 'scalar';
    const [inputType, returnType, extra] = rawType.split(':');
    const normalizedInputType = validCustomTagInputTypes.find((validType) => validType === inputType);
    if (extra || !normalizedInputType)
        return undefined;
    if (!rawType.includes(':')) {
        return { tag, inputType: normalizedInputType };
    }
    const normalizedReturnType = customTagReturnTypeAliases[returnType];
    if (!normalizedReturnType)
        return undefined;
    return { tag, inputType: normalizedInputType, returnType: normalizedReturnType };
}
export function getCustomTagReturnType(node) {
    if (!node || typeof node !== 'object') {
        return undefined;
    }
    const returnType = node.customTagReturnType;
    if (typeof returnType !== 'string') {
        return undefined;
    }
    return Object.values(customTagReturnTypeAliases).includes(returnType)
        ? returnType
        : undefined;
}
export function setCustomTagReturnType(node, returnType) {
    if (returnType && node && typeof node === 'object') {
        node.customTagReturnType = returnType;
    }
}
//# sourceMappingURL=customTags.js.map