import json
import yaml


def get_content(extra_file):
    """Get serialized content based on content_type.

    Args:
        extra_file (Dict[str, Union[str, Dict[Any]]]): The extra file
            configuration.

    Returns:
        str: Serialized content based on the content_type.

    """
    content_type = extra_file.get("content_type")
    content = extra_file.get("content")

    if content:
        if isinstance(content, (dict, list)):
            if content_type == "application/json":
                return json.dumps(content)

            if content_type == "text/yaml":
                return yaml.safe_dump(content)

            raise ValueError(
                '"content_type" must be json or yaml if "content" is not a string'
            )

        if not isinstance(content, str):
            raise TypeError("unsupported content: %s" % type(content))

    return content