"""Factory function for creating event bus instances."""

from typing import Any

from .base import EventBus
from .nats_bus import NATSEventBus


def create_event_bus(bus_type: str, **kwargs: Any) -> EventBus:
    """Factory function to create event bus"""
    if bus_type.lower() == "kafka":
        # Lazy import to avoid ModuleNotFoundError when aiokafka is not installed
        from .contrib.kafka_bus import KafkaEventBus

        return KafkaEventBus(kwargs.get("bootstrap_servers", "localhost:9092"))
    if bus_type.lower() == "sqs":
        # Lazy import to avoid ModuleNotFoundError when boto3 is not installed
        from .contrib.sqs_bus import SQSEventBus

        return SQSEventBus(kwargs.get("region_name", "us-east-1"))
    if bus_type.lower() == "nats":
        return NATSEventBus(
            servers=kwargs.get("servers", "nats://localhost:4222"),
            stream_name=kwargs.get("stream_name", "TAX_AGENT_EVENTS"),
            consumer_group=kwargs.get("consumer_group", "tax-agent"),
        )
    raise ValueError(f"Unsupported event bus type: {bus_type}")
