"""Event utility functions for Lattice.

Pure logic for event type mapping and processing.
All functions are Core layer — no I/O, only @pre/@post + doctests.
"""

from __future__ import annotations

import deal

from lattice.core.types.enums import Role


@deal.pre(lambda event_type: isinstance(event_type, str) and len(event_type) > 0)
@deal.post(lambda result: isinstance(result, Role))
def map_event_type_to_role(event_type: str) -> Role:
    """Map event type string to Role enum.

    Simple structural grouping for event-to-role mapping.
    'reasoning' should be filtered before calling (filtered at SQL level).

    Args:
        event_type: Event type string from events table (e.g., "user", "assistant", "tool").

    Returns:
        Role enum value. Unknown types default to USER.

    >>> map_event_type_to_role("user")
    <Role.USER: 'user'>
    >>> map_event_type_to_role("assistant")
    <Role.ASSISTANT: 'assistant'>
    >>> map_event_type_to_role("tool")
    <Role.TOOL: 'tool'>
    >>> map_event_type_to_role("unknown")
    <Role.USER: 'user'>
    >>> map_event_type_to_role("custom_type")
    <Role.USER: 'user'>
    """
    if event_type == "user":
        return Role.USER
    elif event_type == "assistant":
        return Role.ASSISTANT
    elif event_type == "tool":
        return Role.TOOL
    else:
        # Unknown type: default to USER
        return Role.USER


__all__ = [
    "map_event_type_to_role",
]
