def _build_collection_ids_condition(
    target_column: str,  # Should always be 'collection_ids' when called
    op: str,
    value: Any,
    param_helper: ParamHelper,
) -> str:  # type: ignore
    """Builds SQL condition for the 'collection_ids' UUID[] array column."""
    if target_column != "collection_ids":
        raise FilterError(
            f"Internal Error: _build_collection_ids_condition called with target '{target_column}'"
        )

    # --- Operators requiring a list of UUIDs ---
    if op in [
        FilterOperator.OVERLAP,
        FilterOperator.ARRAY_CONTAINS,
        FilterOperator.IN,
        FilterOperator.NIN,
    ]:
        if not isinstance(value, list):
            raise FilterError(
                f"Operator '{op}' on '{target_column}' requires a list of UUID strings."
            )

        if not value:  # Empty list handling
            if op == FilterOperator.OVERLAP or op == FilterOperator.IN:
                return "FALSE"
            if op == FilterOperator.ARRAY_CONTAINS:
                return "TRUE"  # Contains all elements of an empty set is true
            if op == FilterOperator.NIN:
                return "TRUE"

        # Validate and convert values to UUID strings for the ARRAY constructor
        try:
            uuid_strings = [str(uuid.UUID(str(item))) for item in value]
        except (ValueError, TypeError) as e:
            raise FilterError(
                f"Invalid UUID format in list for '{target_column}' filter: {e}"
            ) from e

        array_literal = _build_array_literal(
            uuid_strings, param_helper, "uuid"
        )

        if (
            op == FilterOperator.OVERLAP or op == FilterOperator.IN
        ):  # IN on array means overlap
            return f"{target_column} && {array_literal}"
        elif (
            op == FilterOperator.ARRAY_CONTAINS
        ):  # Check if target_column contains ALL elements in value
            return f"{target_column} @> {array_literal}"
        elif (
            op == FilterOperator.NIN
        ):  # Check if target_column contains NONE of the elements in value
            return f"NOT ({target_column} && {array_literal})"

    # --- Operators requiring a single UUID (Less common for arrays, interpret carefully) ---
    elif (
        op == FilterOperator.EQ
    ):  # Check if array IS EXACTLY this single element array
        if isinstance(value, (str, uuid.UUID)):
            try:
                uuid_str = str(uuid.UUID(str(value)))
                placeholder = param_helper.add(uuid_str)
                return f"{target_column} = ARRAY[{placeholder}]::uuid[]"
            except (ValueError, TypeError) as e:
                raise FilterError(
                    f"Invalid UUID format for '{op}' on '{target_column}': {e}"
                ) from e
        else:
            raise FilterError(
                f"Operator '{op}' on '{target_column}' requires a single UUID string value."
            )

    elif (
        op == FilterOperator.NE
    ):  # Check if array IS NOT EXACTLY this single element array
        if isinstance(value, (str, uuid.UUID)):
            try:
                uuid_str = str(uuid.UUID(str(value)))
                placeholder = param_helper.add(uuid_str)
                return f"{target_column} != ARRAY[{placeholder}]::uuid[]"
            except (ValueError, TypeError) as e:
                raise FilterError(
                    f"Invalid UUID format for '{op}' on '{target_column}': {e}"
                ) from e
        else:
            raise FilterError(
                f"Operator '{op}' on '{target_column}' requires a single UUID string value."
            )

    raise FilterError(
        f"Unsupported operator '{op}' for array column '{target_column}'."
    )
Builds SQL condition for the 'collection_ids' UUID[] array column.
py/core/providers/database/filters.py