#!/bin/bash

# the script comment out the 'Functions' section in generated markdown file
# also add the 'Generated by 'make udf_doc_gen'.  DO NOT EDIT!' notice at top of comment

set -eE

PATCH_FILE=$1

if [ ! -r "$PATCH_FILE" ]; then
    echo "$PATCH_FILE not available"
    exit 1
fi

sed -i"" -e "1s/^/<!--\nGenerated by 'make udf_doc_gen'.  DO NOT EDIT!\n/" "$PATCH_FILE"

# generate the new header
# also add extra help infos in additional to function docs
sed -i"" -e "s/## Functions Documentation/## Functions Documentation\n\
-->\n\
# Built-in Functions\n\
\n\
## Must read\n\
\n\
Types in documents here may a little different from real types in OpenMLDB SQL, for the purpose of simplify. Those type are synonymics.\n\
\n\
| Type literal | Same as any of those types in OpenMLDB SQL |\n\
| ---------    | --------------------------------------     |\n\
| \`number\`       | \`int16, int32, int64, float, double\`  |\n\
| \`any\`          | \`bool, int16, int32, int64, float, double, string, timestamp, date\` |\n\
| \`list<number>\` | \`list<int16>, list<int32>, list<int64>, list<float>, list<double>\` |\n\
| \`list<any>\`    | \`list<bool>, list<int16>, list<int32>, list<int64>, list<float>, list<double>, list<string>, list<timestamp>, list<date>\` |\n\
\n\
## Functions/g" "$PATCH_FILE"
