from typing import Dict
from typing import Tuple


def get_midfight_survival(med_id3: str, gamelog: Dict) -> Tuple:
    """
    gets the midfight survivals and the midfight deaths from a gamelog for a
    medic player.  If the map isn't a koth or control points map, it returns
    (0,0) because other map types like payload do not have midfights.
    """
    game_map = gamelog["info"]["map"]
    if not game_map.startswith("koth_") and not game_map.startswith("cp_"):
        return (0, 0)
    midfight_deaths = 0  # type: int
    midfight_escapes = 0  # type: int
    for r in gamelog["rounds"]:
        med_round = any([
            a for a in r["events"] if a["type"] in {"medic_death", "charge"}
            and a["steamid"] == med_id3
        ])
        if not med_round:
            continue

        events = [
            a for a in r["events"] if a["type"] == "pointcap" or (
                a["type"] == "medic_death" and a["steamid"] == med_id3)
        ]
        if not events:
            # the game ended before pointcap
            midfight_escapes += 1
        elif events[0]["type"] == "pointcap":
            midfight_escapes += 1
        else:
            midfight_deaths += 1
    return (midfight_escapes, midfight_deaths)