# app/services/messaging.py
"""
Messaging service for auth service
"""
from shared.messaging.rabbitmq import RabbitMQClient
from app.core.config import settings
import structlog

logger = structlog.get_logger()

# Single global instance
auth_publisher = RabbitMQClient(settings.RABBITMQ_URL, "auth-service")

async def setup_messaging():
    """Initialize messaging for auth service"""
    success = await auth_publisher.connect()
    if success:
        logger.info("Auth service messaging initialized")
    else:
        logger.warning("Auth service messaging failed to initialize")

async def cleanup_messaging():
    """Cleanup messaging for auth service"""
    await auth_publisher.disconnect()
    logger.info("Auth service messaging cleaned up")

# Convenience functions for auth-specific events
async def publish_user_registered(user_data: dict) -> bool:
    """Publish user registered event"""
    return await auth_publisher.publish_user_event("registered", user_data)

async def publish_user_login(user_data: dict) -> bool:
    """Publish user login event"""
    return await auth_publisher.publish_user_event("login", user_data)

async def publish_user_logout(user_data: dict) -> bool:
    """Publish user logout event"""
    return await auth_publisher.publish_user_event("logout", user_data)

async def publish_user_updated(user_data: dict) -> bool:
    """Publish user updated event"""
    return await auth_publisher.publish_user_event("updated", user_data)

async def publish_user_deactivated(user_data: dict) -> bool:
    """Publish user deactivated event"""
    return await auth_publisher.publish_user_event("deactivated", user_data)
