MINIO_URL="$1"
MINIO_ALIAS="$2"

OUTPUT=$(cat <<EOF
$3
EOF
)

IDS=""
URLS=""
TAGS=""
while read -r line; do
    if [[ $line == "Name"* ]]; then
        # Collapes the spaces.
        COLLAPSED=$(echo "$line" | tr -s " ")
        # Split the string by spaces.
        URL=$(echo "$COLLAPSED" | cut -d " " -f 3)
        ID=$(echo "$COLLAPSED" | cut -d " " -f 4 | tr -d "()")
        URLS+="$URL "
        IDS+="$ID "
        TAGS="${TAGS%?} "
    else
        VARNAME=$(echo "$line" | cut -d ":" -f 1 | xargs)
        VARVAL=$(echo "$line" | cut -d ":" -f 2 | xargs)
        TAGS+="$VARNAME=$VARVAL&"
    fi
done <<< "$OUTPUT"
# Remove last amperstand.
TAGS=$(echo "${TAGS%?}")
# Remove first space.
TAGS=$(echo "${TAGS/ /}")
URLS=$(echo "$URLS" | xargs)
ALIASED_URLS=$(echo "$URLS" | sed -e "s|^$MINIO_URL|$MINIO_ALIAS|g" | xargs)

echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
echo "urls=$URLS" >> "$GITHUB_OUTPUT"
echo "aliasedUrls=$ALIASED_URLS" >> "$GITHUB_OUTPUT"