from typing import Dict
from typing import Any


def map_dict_keys(obj: Dict, map_rules: Dict[str, str], only_given_fields: bool = False) -> Dict[Any, Any]:
    """
    This function will switch the keys of a dictionary according to the provided map_rules.
    Example: map_dict_keys( {'a' : 'b', 'c' : 'd' }, {'a' : 'y', 'c' : 'z' }) -> {'y' : 'b' , 'z' : 'd'}
    Args:
        obj: The original dictionary
        map_rules: The mapping the keys should be changed by
        only_given_fields: whether fields besides for those in map_rules should be used
    Returns : a Dict according to the map_rules
    """
    return {map_rules.get(key, key): obj[key] for key in obj.keys() if not only_given_fields or key in map_rules}