#!/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

# Get tokens
echo "Updating severity column..."
# Update severity column (ID: cv1al80v3ejvij0)
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cv1al80v3ejvij0" \
  -H "xc-token: $NOCODB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "dtxp": "error,warning,auto-correct",
    "meta": {
      "options": [
        {"title": "error", "color": "#FF0000"},
        {"title": "warning", "color": "#FFA500"},
        {"title": "auto-correct", "color": "#FFFF00"}
      ]
    }
  }'
echo ""
echo "Updating status column..."
# Update status column (ID: cxbxnyh03nkvd0a)
curl -s -X PATCH "http://192.168.25.5:8080/api/v2/meta/columns/cxbxnyh03nkvd0a" \
  -H "xc-token: $NOCODB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "dtxp": "active,reversed,deprecated",
    "meta": {
      "options": [
        {"title": "active", "color": "#00FF00"},
        {"title": "reversed", "color": "#FFA500"},
        {"title": "deprecated", "color": "#808080"}
      ]
    }
  }'
echo ""
echo "Done!"
