code: def _textualize_state_transitions(
      desired_state: V1LightningappInstanceState,
      current_state: V1LightningappInstanceStatus,
  ) -> Text:
      phases = {
          V1LightningappInstanceState.IMAGE_BUILDING: Text(
              "building image", style="bold yellow"
          ),
          V1LightningappInstanceState.PENDING: Text(
              "pending", style="bold yellow"
          ),
          V1LightningappInstanceState.RUNNING: Text(
              "running", style="bold green"
          ),
          V1LightningappInstanceState.FAILED: Text(
              "failed", style="bold red"
          ),
          V1LightningappInstanceState.STOPPED: Text("stopped"),
          V1LightningappInstanceState.NOT_STARTED: Text("not started"),
          V1LightningappInstanceState.DELETED: Text(
              "deleted", style="bold red"
          ),
          V1LightningappInstanceState.UNSPECIFIED: Text(
              "unspecified", style="bold red"
          ),
      }
  
      if (
          current_state.phase == V1LightningappInstanceState.UNSPECIFIED
          and current_state.start_timestamp is None
      ):
          return Text("not yet started", style="bold yellow")
  
      if (
          desired_state == V1LightningappInstanceState.DELETED
          and current_state.phase != V1LightningappInstanceState.DELETED
      ):
          return Text("terminating", style="bold red")
  
      if (
          any(
              phase == current_state.phase
              for phase in [
                  V1LightningappInstanceState.PENDING,
                  V1LightningappInstanceState.STOPPED,
              ]
          )
          and desired_state == V1LightningappInstanceState.RUNNING
      ):
          return Text("restarting", style="bold yellow")
  
      return phases[current_state.phase]
  
imports: import json
  from datetime import datetime
  from typing import List, Optional
  from lightning_cloud.openapi import Externalv1LightningappInstance, Externalv1Lightningwork, V1LightningappInstanceState, V1LightningappInstanceStatus
  from rich.console import Console
  from rich.table import Table
  from rich.text import Text
  from lightning.app.cli.core import Formatable
  from lightning.app.utilities.cloud import _get_project
  from lightning.app.utilities.network import LightningClient
label_desc: Use image node_id 2 for calling the _AppList obj's underlying member method code with example usage: obj._textualize_state_transitions(desired_state, current_state) and returns: phases, Text, Text, Text