"""
Temporal worker entrypoint for the team-created workflow.
"""
import asyncio
import logging
import os
from concurrent.futures import ThreadPoolExecutor

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

from . import activities
from .workflows import TeamCreatedWorkflow

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


async def main() -> None:
    target = os.environ.get("TEMPORAL_ADDRESS", "localhost:7233")
    namespace = os.environ.get("TEMPORAL_NAMESPACE", "default")
    task_queue = os.environ.get("TEMPORAL_TASK_QUEUE", "teams-team-created")

    logger.info("Connecting to Temporal at %s (ns=%s)", target, namespace)
    client = await Client.connect(target, namespace=namespace)

    logger.info("Starting worker on task queue: %s", task_queue)
    worker = Worker(
        client,
        task_queue=task_queue,
        workflows=[TeamCreatedWorkflow],
        activities=[activities.create_kyc_in_odoo],
        activity_executor=ThreadPoolExecutor(max_workers=10),
    )

    await worker.run()


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