from typing import List
import yaml


def get_workflow_step_names(workflow_content: bytes) -> List[str]:
    """Takes a CWL workflow and extracts names of steps.

    This assumes that the steps are not inlined, but referenced by
    name, as we require for workflows submitted to Cerise. Also, this
    is not the name of the step in the workflow document, but the name
    of the step in the API to run. It's the content of the ``run``
    attribute, not that of the ``id`` attribute.

    Args:
        workflow_content: The contents of the workflow file.

    Returns:
        A list of step names.
    """
    workflow = yaml.safe_load(workflow_content.decode())
    if 'class' not in workflow or workflow['class'] != 'Workflow':
        raise RuntimeError('Invalid workflow file')
    if 'steps' not in workflow:
        raise RuntimeError('Invalid workflow file')

    steps = None
    if isinstance(workflow['steps'], dict):
        steps = list(workflow['steps'].values())
    elif isinstance(workflow['steps'], list):
        steps = workflow['steps']

    if steps is None:
        raise RuntimeError('Invalid workflow file')

    return [step['run'] for step in steps]