#!/bin/bash
# get-columns.sh - List NocoDB columns for a table
# Uses vault cache for fast token retrieval

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/../vault-env.sh"

NOCODB_TOKEN=$(vault_nocodb_token)
TABLE_ID="${1:-mx149yctebfwvys}"

if [ -z "$NOCODB_TOKEN" ]; then
    echo "Error: Could not retrieve NocoDB token"
    exit 1
fi

echo "=== Columns for table ${TABLE_ID} ==="
curl -s "http://192.168.25.5:8080/api/v2/tables/${TABLE_ID}/columns" \
  -H "xc-token: ${NOCODB_TOKEN}" | jq -r '.list[] | "\(.id): \(.title) (\(.uidt))"' 2>/dev/null || echo "Failed to get columns"
