code: def downgrade(
      all_: bool,  # pylint: disable=unused-argument
      dashboard_ids: tuple[int, ...],
  ) -> None:
      """
      Downgrade native dashboard filters to legacy filter-box charts (where applicable).
      """
  
      # Mapping between the MARKDOWN- and CHART- IDs.
      mapping = {}
  
      for dashboard in (  # pylint: disable=too-many-nested-blocks
          db.session.query(Dashboard)
          .filter(
              *[Dashboard.id.in_(dashboard_ids)]
              if dashboard_ids
              else []
          )
          .all()
      ):
          click.echo(f"Downgrading {str(dashboard)}")
  
          try:
              json_metadata = json.loads(
                  dashboard.json_metadata or "{}"
              )
              position_json = json.loads(
                  dashboard.position_json or "{}"
              )
  
              if "native_filter_migration" not in json_metadata:
                  click.echo(f"{str(dashboard)} has not been upgraded")
                  continue
  
              # Restore the native and legacy filter configurations.
              for key in (
                  "default_filters",
                  "filter_scopes",
                  "native_filter_configuration",
              ):
                  json_metadata.pop(key, None)
  
              json_metadata.update(
                  json_metadata.pop("native_filter_migration")
              )
  
              # Replace the relevant markdown elements with filter-box charts.
              slice_ids = set()
  
              for key, value in list(
                  position_json.items()
              ):  # Immutable iteration
                  if (
                      isinstance(value, dict)
                      and value["type"] == "MARKDOWN"
                      and (meta := value.get("meta"))
                      and "native_filter_migration" in meta
                  ):
                      meta.update(meta.pop("native_filter_migration"))
                      slice_ids.add(meta["chartId"])
                      mapping[key] = key.replace("MARKDOWN-", "CHART-")
                      value["id"] = mapping[key]
                      del meta["code"]
                      value["type"] = "CHART"
                      position_json[mapping[key]] = value
                      del position_json[key]
  
              # Replace the relevant CHART- references.
              for value in position_json.values():
                  if isinstance(value, dict):
                      for relation in ["children", "parents"]:
                          if relation in value:
                              for idx, key in enumerate(
                                  value[relation]
                              ):
                                  if key in mapping:
                                      value[relation][idx] = mapping[
                                          key
                                      ]
  
              # Restore the filter-box charts to the dashboard/slice mapping.
              for slc in (
                  db.session.query(Slice)
                  .filter(Slice.id.in_(slice_ids))
                  .all()
              ):
                  dashboard.slices.append(slc)
  
              dashboard.json_metadata = json.dumps(json_metadata)
              dashboard.position_json = json.dumps(position_json)
          except Exception:  # pylint: disable=broad-except
              click.echo(f"Unable to downgrade {str(dashboard)}")
  
      db.session.commit()
      db.session.close()
  
file_path: superset/superset/cli/native_filters.py
imports: import json
  from copy import deepcopy
  from textwrap import dedent
  import click
  from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
  from flask.cli import with_appcontext
  from sqlalchemy import Column, ForeignKey, Integer, String, Table, Text
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.orm import relationship
  from superset import db, is_feature_enabled
label_desc: Use image node_id 3 for calling a global function with example usage: downgrade(all_, dashboard_ids) without return types