import asyncio
from typing import Tuple

from temporalio.client import Client

from .types import TeamCreatedInput
from .workflows import TeamCreatedWorkflow


async def start_team_created_async(
    data: TeamCreatedInput,
    address: str = "localhost:7233",
    namespace: str = "default",
    task_queue: str = "teams-team-created",
) -> Tuple[str, str]:
    """
    Start TeamCreatedWorkflow and return (workflow_id, run_id).
    """
    client = await Client.connect(address, namespace=namespace)
    handle = await client.start_workflow(
        TeamCreatedWorkflow.run,
        data,
        id=data.team_id,
        task_queue=task_queue,
    )
    return handle.id, handle.run_id


def start_team_created(
    data: TeamCreatedInput,
    address: str = "localhost:7233",
    namespace: str = "default",
    task_queue: str = "teams-team-created",
) -> Tuple[str, str]:
    """
    Synchronous wrapper for environments that prefer sync code (e.g., Django views).
    """
    return asyncio.run(
        start_team_created_async(
            data=data,
            address=address,
            namespace=namespace,
            task_queue=task_queue,
        )
    )
