text: from __future__ import annotations
  
  from typing import Dict, Optional
  
  from argo.workflows.client import V1alpha1Workflow
  from pydantic import BaseModel
  
  
  def _get_workflow_name(response_dict: Dict[str, any]) -> Optional[str]:
      return response_dict.get("metadata").get("name")
  
  
  def _get_workflow_uid(response_dict: Dict[str, any]) -> Optional[str]:
      return response_dict.get("metadata").get("uid")
  
  
  def _get_workflow_type(response_dict: Dict[str, any]) -> Optional[str]:
      """
      The workflow is named after its type,
      i.e. the workflow "verify-overforingspakke" has the type value "verify-overforingspakke"
  
      Our naming convention is to name this initializing node with the same name as the name of the whole workflow,
      i.e. we can always use the name of the entrypoint to equal the name of the workflow.
      """
      return response_dict.get("spec").get("entrypoint")
  
  
  def _get_argo_workflow_parameter(parameter_key: str, response_dict: Dict[str, any]) -> Optional[str]:
      """
      When initiating an argo workflow you can send in parameters on the format {"name": "X", "value": "Y"}.
      These parameters are stored in the response object returned when starting an argo workflow
      as a list of dictionaries under "spec.arguments.parameters".
  
      Return: the string value of the argument, (the "Y" in {"name": "X", "value": "Y"}
      """
      params = response_dict.get("spec").get("arguments").get("parameters")
      for param in params:
          if param["name"] == parameter_key:
              return param["value"]
      return None
  
  
  def _get_invitasjon_ekstern_id(response_dict: Dict[str, any]) -> Optional[str]:
      """
      The invitasjon_ekstern_id is known as "EKSTERN_ID" in the context of tusd and can be found
      as a parameter under that name here.
  
      Return: String containing the invitasjon_ekstern_id
      """
      return _get_argo_workflow_parameter("EKSTERN_ID", response_dict)
  
  
  def _get_target_bucket(response_dict: Dict[str, any]) -> Optional[str]:
      """
      Parameter key for target_bucket = TARGET_BUCKET
      """
      return _get_argo_workflow_parameter("TARGET_BUCKET", response_dict)
  
  
  def _get_overforingspakke_id(response_dict: Dict[str, any]) -> Optional[str]:
      """
      Parameter key for overforingspakke_id = OVERFORINGSPAKKE_ID
      """
      return _get_argo_workflow_parameter("OVERFORINGSPAKKE_ID", response_dict)
  
  
  class ArgoWorkflowResponse(BaseModel):
      workflow_name: str
      workflow_uid: str
      workflow_type: str
      invitasjon_ekstern_id: Optional[str] = None
      target_bucket: Optional[str] = None
      overforingspakke_id: Optional[int] = None
  
      @staticmethod
      def from_argo_server_response(argo_server_response: V1alpha1Workflow) -> ArgoWorkflowResponse:
          response_dict = argo_server_response.to_dict()
          workflow_name = _get_workflow_name(response_dict)
          workflow_uid = _get_workflow_uid(response_dict)
          workflow_type = _get_workflow_type(response_dict)
  
          invitasjon_ekstern_id = _get_invitasjon_ekstern_id(response_dict)
          target_bucket = _get_target_bucket(response_dict)
          overforingspakke_id = _get_overforingspakke_id(response_dict)
  
          return ArgoWorkflowResponse(
              workflow_name=workflow_name,
              workflow_uid=workflow_uid,
              workflow_type=workflow_type,
              invitasjon_ekstern_id=invitasjon_ekstern_id,
              target_bucket=target_bucket,
              overforingspakke_id=overforingspakke_id,
          )
  