#!/usr/bin/env python3
"""
Complete workflow for Card #913 fix.

This demonstrates the required steps:
1. Fetch card via mcp__trello__get_card
2. Parse description
3. Apply permissions
4. Return structured results
"""
import json
import sys

# For demonstration, we'll show what the workflow expects
# In practice, this is called by Claude Code with MCP context

CARD_ID = "6a1d693f049c86ebcbdacbc8"
CARD_SHORT = 913

# Example card description (what mcp__trello__get_card would return)
# This needs to be fetched via the MCP tool in the actual workflow
EXAMPLE_DESCRIPTION = """
en: https://docs.google.com/document/d/1EN_DOC_ID_HERE/edit
it: https://docs.google.com/document/d/1IT_DOC_ID_HERE/edit
de: https://docs.google.com/document/d/1DE_DOC_ID_HERE/edit
es: https://docs.google.com/document/d/1ES_DOC_ID_HERE/edit
pt: https://docs.google.com/document/d/1PT_DOC_ID_HERE/edit
fr: https://docs.google.com/document/d/1FR_DOC_ID_HERE/edit
"""

def main():
    print("""
WORKFLOW FOR CARD #913:

Step 1: Fetch card via mcp__trello__get_card
  Tool: mcp__trello__get_card
  Input: {"cardId": "6a1d693f049c86ebcbdacbc8", "includeMarkdown": true}
  Output: card.desc (card description containing Google Docs links)

Step 2: Parse description to extract language -> docId mapping
  Parse each line like: "en: https://docs.google.com/document/d/DOCID/edit"
  Skip "fr" entries

Step 3: For each non-FR language, call _share_fix.py:
  Command: python3 _share_fix.py share <docId>
  For each language in sorted order:
    - en -> share <docId> -> role "writer" 
    - de -> share <docId> -> role "writer"
    - es -> share <docId> -> role "writer"
    - it -> share <docId> -> role "writer"
    - pt -> share <docId> -> role "writer"

Step 4: Collect results in format:
{
  "cardShort": 913,
  "results": [
    {"lang": "de", "role": "writer", "changed": "promoted|created|already"},
    {"lang": "en", "role": "writer", "changed": "promoted|created|already"},
    {"lang": "es", "role": "writer", "changed": "promoted|created|already"},
    {"lang": "it", "role": "writer", "changed": "promoted|created|already"},
    {"lang": "pt", "role": "writer", "changed": "promoted|created|already"}
  ],
  "allWriter": true,
  "problems": []
}
""")
    
    # Return the expected structure when no problems found
    result = {
        "cardShort": CARD_SHORT,
        "results": [],  # Will be populated by actual execution
        "allWriter": False,  # Depends on actual permissions
        "problems": ["requires_mcp_trello_fetch"]  # Indicates MCP call needed
    }
    
    print(json.dumps(result, indent=2), file=sys.stderr)
    return 1

if __name__ == "__main__":
    sys.exit(main())
