#!/bin/bash
# Uses vault cache for fast token retrieval

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

NOCODB_TOKEN=$(vaul…ken)

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

echo "Getting current column config..."
# Get current column
curl -s "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
  -H "xc-token: $NOCODB_TOKEN" | jq '.colOptions'
echo ""
echo "Updating colOptions for type column..."
# Update colOptions via the options endpoint
curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc/colOptions/options" \
  -H "xc-token: $NOCODB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "options": [
      {"title": "correction", "color": "#FF0000"},
      {"title": "preference", "color": "#00FF00"},
      {"title": "episode", "color": "#0000FF"},
      {"title": "decision", "color": "#FFFF00"},
      {"title": "validation", "color": "#FF00FF"}
    ]
  }'
echo ""
echo "Done!"
