code: def prepare_nql_query(
      ids: Optional[Iterable[str]],
      states: Optional[Iterable[str]],
      owners: Optional[Iterable[str]],
      tags: Optional[Iterable[str]],
      trashed: Optional[bool],
  ) -> NQLQueryAggregate:
      query_items: List[
          Union[NQLQueryAttribute, NQLQueryAggregate]
      ] = []
  
      if trashed is not None:
          query_items.append(
              NQLQueryAttribute(
                  name="sys/trashed",
                  type=NQLAttributeType.BOOLEAN,
                  operator=NQLAttributeOperator.EQUALS,
                  value=trashed,
              )
          )
  
      if ids:
          query_items.append(
              NQLQueryAggregate(
                  items=[
                      NQLQueryAttribute(
                          name="sys/id",
                          type=NQLAttributeType.STRING,
                          operator=NQLAttributeOperator.EQUALS,
                          value=api_id,
                      )
                      for api_id in ids
                  ],
                  aggregator=NQLAggregator.OR,
              )
          )
  
      if states:
          query_items.append(
              NQLQueryAggregate(
                  items=[
                      NQLQueryAttribute(
                          name="sys/state",
                          type=NQLAttributeType.EXPERIMENT_STATE,
                          operator=NQLAttributeOperator.EQUALS,
                          value=RunState.from_string(state).to_api(),
                      )
                      for state in states
                  ],
                  aggregator=NQLAggregator.OR,
              )
          )
  
      if owners:
          query_items.append(
              NQLQueryAggregate(
                  items=[
                      NQLQueryAttribute(
                          name="sys/owner",
                          type=NQLAttributeType.STRING,
                          operator=NQLAttributeOperator.EQUALS,
                          value=owner,
                      )
                      for owner in owners
                  ],
                  aggregator=NQLAggregator.OR,
              )
          )
  
      if tags:
          query_items.append(
              NQLQueryAggregate(
                  items=[
                      NQLQueryAttribute(
                          name="sys/tags",
                          type=NQLAttributeType.STRING_SET,
                          operator=NQLAttributeOperator.CONTAINS,
                          value=tag,
                      )
                      for tag in tags
                  ],
                  aggregator=NQLAggregator.AND,
              )
          )
  
      query = NQLQueryAggregate(
          items=query_items, aggregator=NQLAggregator.AND
      )
      return query
  
imports: from typing import Iterable, List, Optional, Union
  from neptune.internal.backends.nql import NQLAggregator, NQLAttributeOperator, NQLAttributeType, NQLQueryAggregate, NQLQueryAttribute
  from neptune.internal.utils.run_state import RunState
label_desc: Use image node_id 1 for calling a global function with example usage: prepare_nql_query(ids, states, owners, tags, trashed) and returns: query