#!/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 "Deleting type column..."
# Delete the type column
curl -s -X DELETE "http://192.168.25.5:8080/api/v2/meta/columns/ctkqqemeblx80cc" \
  -H "xc-token: $NOCODB_TOKEN"
echo ""
echo "Recreating type column with options..."
# Create new SingleSelect column with options
curl -s -X POST "http://192.168.25.5:8080/api/v2/meta/tables/mx149yctebfwvys/columns" \
  -H "xc-token: $NOCODB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "column_name": "type",
    "title": "type",
    "uidt": "SingleSelect",
    "dtxp": "correction,preference,episode,decision,validation"
  }'
echo ""
echo "Done!"
