import six


def ParseStateMetadata(metadata, message_request):
  """Parsing args to get full state metadata string.

  Args:
      metadata: dict, key-value pairs passed in from the --metadata flag.
      message_request: specific request field of message module

  Returns:
      A message object.
  """
  if not metadata:
    return None

  additional_properties = []

  metadata_value_msg = message_request.StateMetadataValue

  for key, value in six.iteritems(metadata):
    additional_properties.append(
        metadata_value_msg.AdditionalProperty(key=key, value=value))

  return metadata_value_msg(additionalProperties=additional_properties) or None