from typing import List
from typing import Dict
from typing import Set


def get_unique_related_host_ids(security_problems: List[Dict]) -> Set[str]:
    """Extract all unique related host IDs from a list of security problems.
    :param security_problems: the security problems, parsed from JSON to Dicts of Dicts
    :return: the set of unique related host IDs across all provided security problems
    """
    if not all(['relatedEntities' in x for x in security_problems]):
        raise ValueError("Security problems need to contain 'relatedEntities'")
    if not all(['hosts' in x['relatedEntities'] for x in security_problems]):
        raise ValueError("Security problems need to contain 'relatedEntities'->'hosts'")
    if not all(['affectedEntities' in y for x in security_problems for y in x['relatedEntities']['hosts']]):
        raise ValueError("Security problems need to contain 'relatedEntities'->'hosts'->'affectedEntities'")
    return {entry['id'] for sp in security_problems for entry in sp['relatedEntities']['hosts']}