"""Global store for NLG responses that can be updated at runtime."""

from typing import Any, Dict, List, Text

import structlog

structlogger = structlog.get_logger()

# Global dictionary that stores responses and can be referenced by agent.nlg
_global_responses: Dict[Text, List[Dict[Text, Any]]] = {}


def get_global_responses() -> Dict[Text, List[Dict[Text, Any]]]:
    """Get the global responses dictionary.

    This returns the actual dictionary reference, not a copy.
    Any modifications to the returned dict will affect the global store.

    Returns:
        The global responses dictionary.
    """
    return _global_responses


def update_global_responses(responses: Dict[Text, List[Dict[Text, Any]]]) -> None:
    """Update the global responses dictionary.

    This clears the existing responses and updates with new ones,
    preserving the same dictionary reference.

    Args:
        responses: New responses to store.
    """
    global _global_responses
    _global_responses.clear()
    _global_responses.update(responses)
    structlogger.info(
        "responses_store.updated",
        response_count=len(responses),
        response_keys=list(responses.keys())[:10],  # Log first 10 keys
    )


def clear_global_responses() -> None:
    """Clear all responses from the global store."""
    global _global_responses
    _global_responses.clear()
    structlogger.info("responses_store.cleared")
