#!/bin/bash

# This script orchestrates the card 903 fix
# Step 1: We need to fetch the card description somehow
# Since MCP tools are available, we'll try to invoke them

# For now, let's create a wrapper that assumes card data will come via stdin or we'll
# provide it manually

CARD_ID="6a1d64126a923744238639f9"
SCRIPT_PATH="/opt/automator/cinik-writer-transtor/files/RUN_CARD_921_SHARE_FIX.py"

# Try option 1: Use the existing script with manual card data
# First, let's try to make a direct Trello API call if we have node

if command -v node &> /dev/null; then
    # Try to invoke via MCP socket - this might work if Claude Code is running
    cat > /tmp/fetch_card.js << 'JSEOF'
const fs = require('fs');
const path = require('path');

// Check if we can access MCP or Trello API
const trelloConfigPath = path.expandUser('~/.trello-mcp/config.json');
console.error(`Looking for config at: ${trelloConfigPath}`);

JSEOF
fi

# For now, let's try a simple approach: manually construct the card data
# or use curl with environment variables

if [ -n "$TRELLO_API_KEY" ] && [ -n "$TRELLO_API_TOKEN" ]; then
    echo "Using TRELLO_API_KEY and TRELLO_API_TOKEN from environment" >&2
    curl -s "https://api.trello.com/1/cards/${CARD_ID}?key=${TRELLO_API_KEY}&token=${TRELLO_API_TOKEN}&fields=desc,name" | \
    python3 "${SCRIPT_PATH}"
else
    echo "No Trello API credentials in environment" >&2
    echo "Waiting for card data from stdin..." >&2
    cat | python3 "${SCRIPT_PATH}"
fi

