"""Handler for CameraAimAssistPresetsPacket -- v898 server to v924 client."""

from endstone_endweave.codec import (
    INT_LE,
    STRING,
    UVAR_INT,
    OptionalType,
    PacketWrapper,
)


def rewrite_camera_aim_assist_presets(wrapper: PacketWrapper) -> None:
    """Insert the v924 entity family arrays.

    Args:
        wrapper: Packet wrapper for CameraAimAssistPresets.
    """
    category_count = wrapper.passthrough(UVAR_INT)  # Camera Aim-Assist Categories
    for _ in range(category_count):
        wrapper.passthrough(STRING)  # Identifier

        count = wrapper.passthrough(UVAR_INT)  # Entity Priorities
        for _ in range(count):
            wrapper.passthrough(STRING)
            wrapper.passthrough(INT_LE)

        count = wrapper.passthrough(UVAR_INT)  # Block Priorities
        for _ in range(count):
            wrapper.passthrough(STRING)
            wrapper.passthrough(INT_LE)

        count = wrapper.passthrough(UVAR_INT)  # Entity Tag Priorities
        for _ in range(count):
            wrapper.passthrough(STRING)
            wrapper.passthrough(INT_LE)

        wrapper.write(UVAR_INT, 0)  # Entity Family Priorities (empty for v924)

        wrapper.passthrough(OptionalType(INT_LE))  # Default Entity Priority
        wrapper.passthrough(OptionalType(INT_LE))  # Default Block Priority

    preset_count = wrapper.passthrough(UVAR_INT)  # Camera Aim-Assist Presets
    for _ in range(preset_count):
        wrapper.passthrough(STRING)  # Identifier

        block_exclusion_count = wrapper.passthrough(UVAR_INT)  # Block Exclusions
        for _ in range(block_exclusion_count):
            wrapper.passthrough(STRING)

        entity_exclusion_count = wrapper.passthrough(UVAR_INT)  # Entity Exclusions
        for _ in range(entity_exclusion_count):
            wrapper.passthrough(STRING)

        block_tag_exclusion_count = wrapper.passthrough(UVAR_INT)  # Block Tag Exclusions
        for _ in range(block_tag_exclusion_count):
            wrapper.passthrough(STRING)

        wrapper.write(UVAR_INT, 0)  # Entity Type Family Exclusions (empty for v924)

        liquid_count = wrapper.passthrough(UVAR_INT)  # Liquid Targets
        for _ in range(liquid_count):
            wrapper.passthrough(STRING)

        item_count = wrapper.passthrough(UVAR_INT)  # Item Settings
        for _ in range(item_count):
            wrapper.passthrough(STRING)
            wrapper.passthrough(STRING)

        wrapper.passthrough(OptionalType(STRING))  # Default Category for Hands
        wrapper.passthrough(OptionalType(STRING))  # Default Category for Items
