"""
Centralized path configuration for versioned ER API endpoints.

Paths are keyed by literal API version (e.g. "v1.0", "v2.0") as used in the URL.
"""

VERSION_1_0 = "v1.0"
VERSION_2_0 = "v2.0"
DEFAULT_VERSION = VERSION_1_0

# Event types: path prefix for list/get/post; patch appends identifier (id for v1.0, value for v2.0).
EVENT_TYPES_PATHS = {
    VERSION_1_0: "activity/events/eventtypes",
    VERSION_2_0: "activity/eventtypes",
}


def event_types_list_path(version: str = DEFAULT_VERSION) -> str:
    """Path for listing or posting event types (no trailing segment)."""
    return EVENT_TYPES_PATHS.get(version, EVENT_TYPES_PATHS[DEFAULT_VERSION])


def event_types_patch_path(version: str, event_type: dict) -> str:
    """
    Path for patching an event type.

    v1.0 uses event_type["id"] in the path; v2.0 uses event_type["value"] (slug).
    """
    base = event_types_list_path(version)
    if version == VERSION_2_0:
        try:
            value = event_type['value']
            return f"{base}/{value}"
        except KeyError:
            raise ValueError(f"Event type value is required for v2.0 patching")

    try:
        id = event_type['id']
        return f"{base}/{id}"
    except KeyError:
        raise ValueError(f"Event type id is required for v1.0 patching")


def event_type_detail_path(version: str, value: str) -> str:
    """
    Path for getting a single event type by name/slug.

    v1.0 uses schema path activity/events/schema/eventtype/{value};
    v2.0 uses activity/eventtypes/{value}.
    """
    if version == VERSION_2_0:
        return f"{event_types_list_path(version)}/{value}"
    return f"activity/events/schema/eventtype/{value}"
