#!/bin/sh

# Generate definition_gen.go from definition.go.

set -e

cat <<EOF
// Code generated by definition_gen.sh. DO NOT EDIT.

package schema

import "akvorado/common/helpers/bimap"

var columnNameMap = bimap.New(map[ColumnKey]string{
$(sed -En '/.*ColumnKey = iota/,/^[[:space:]]+ColumnLast/p' common/schema/definition.go \
    | sed \$d \
    | sed -En 's/^[[:space:]]+Column//p' \
    | awk '{ print "Column"$1": \""$1"\","}')
})


var columnReverseTable = [...]ColumnKey{
$(sed -En '/.*ColumnKey = iota/,/^[[:space:]]ColumnLast/p' common/schema/definition.go \
    | sed \$d \
    | sed -En 's/^[[:space:]]+(Column[^ ]+).*/\1/p' \
    | sed -E \
             -e 's/(ColumnDst(ASPath|Communities|LargeCommunities|[123]..AS))/\1: 0,/;t' \
             -e 's/(ColumnIn)([A-Z0-9].*)/ColumnOut\2: \1\2,/;t' \
             -e 's/(ColumnOut)([A-Z0-9].*)/ColumnIn\2: \1\2,/;t' \
             -e 's/(ColumnSrc)([A-Z0-9].*)/ColumnDst\2: \1\2,/;t' \
             -e 's/(ColumnDst)([A-Z0-9].*)/ColumnSrc\2: \1\2,/;t' \
             -e 's/(.*)/\1: \1,/')
}
EOF
