from __future__ import annotations

import asyncio
import os

from temporalio.client import Client
from temporalio.worker import Worker

from gumbo.temporal import activities
from gumbo.temporal.workflows import GumboApprovalGateWorkflow, GumboSummarizeWorkflow


async def _main() -> None:
    address = os.environ.get("TEMPORAL_ADDRESS", "temporal-frontend.ai-core.svc.cluster.local:7233")
    namespace = os.environ.get("TEMPORAL_NAMESPACE", "default")
    task_queue = os.environ.get("GUMBO_TASK_QUEUE", "gumbo")

    client = await Client.connect(address, namespace=namespace)
    worker = Worker(
        client,
        task_queue=task_queue,
        workflows=[GumboSummarizeWorkflow, GumboApprovalGateWorkflow],
        activities=[
            activities.run_gumbo_langgraph_job,
            activities.persist_gumbo_summary,
            activities.parse_gumbo_job_logs,
        ],
    )
    await worker.run()


def main() -> None:
    asyncio.run(_main())


if __name__ == "__main__":
    main()
