import asyncio
import sys

from temporalio.client import Client


async def main():
    if len(sys.argv) < 2:
        print("Usage: python trigger_gumbo.py <object_key>")
        sys.exit(1)
        
    object_key = sys.argv[1]
    
    # Create Temporal client
    # Assuming port-forward or executing inside cluster
    # We will just print instructions to port-forward
    print("Connecting to Temporal server at localhost:7233...")
    try:
        client = await Client.connect("localhost:7233")
    except Exception as e:
        print(f"Failed to connect to Temporal: {e}")
        print("Please ensure you have port-forwarded the Temporal frontend:")
        print("kubectl port-forward svc/temporal-frontend 7233:7233 -n ai-core")
        sys.exit(1)

    print(f"Triggering GumboSummarizeWorkflow for object_key: {object_key}")
    
    # Execute workflow
    # Workflow name must match the class name `GumboSummarizeWorkflow`
    # Task queue is likely 'gumbo-task-queue' based on standard setups
    handle = await client.start_workflow(
        "GumboSummarizeWorkflow",
        object_key,
        id=f"gumbo-summary-{object_key}",
        task_queue="gumbo"
    )

    print(f"Workflow started. Workflow ID: {handle.id}, Run ID: {handle.result_run_id}")
    
    print("Waiting for workflow to complete...")
    result = await handle.result()
    
    print("\n--- Workflow Result ---")
    print(result)

if __name__ == "__main__":
    asyncio.run(main())
