def translate_room(room):
    translations = {
        "room": lambda parts: f"B{parts[1]}0{parts[2]}",
        "dormitory": lambda parts: f"{parts[1]}层宿舍",
        "contact": lambda parts: "办公室",
        "central": lambda parts: "控制中枢",
        "factory": lambda parts: "加工站",
        "meeting": lambda parts: "会客室",
        "train": lambda parts: "训练室",
    }

    for keyword, translation_func in translations.items():
        if keyword in room:
            parts = room.split("_")
            return translation_func(parts)

    return room


action_type_translation = {
    "子弹时间": "BulletTime",
    "部署": "Deploy",
    "二倍速": "SpeedUp",
    "技能": "Skill",
    "技能用法": "SkillUsage",
    "撤退": "Retreat",
    "摆完挂机": "SkillDaemon",
    "打印": "Output",
    "移动镜头": "MoveCamera",
}
direction_translation = {
    "上": "Up",
    "下": "Down",
    "左": "Left",
    "右": "Right",
    "无": "None",
    "up": "Up",
    "down": "Down",
    "left": "Left",
    "right": "Right",
    "none": "None",
}


def translate_direction(direction):
    if direction in direction_translation:
        return direction_translation[direction]
    return direction


def translate_actions(actions):
    for action in actions:
        if "type" in action and action["type"] in action_type_translation:
            action["type"] = action_type_translation[action["type"]]
        if "direction" in action:
            action["direction"] = translate_direction(action["direction"])
    return actions


def pretranslate_work(work):
    work["actions"] = translate_actions(work["actions"])
    return work


profession_translation = {
    "先锋": "PIONEER",
    "近卫": "WARRIOR",
    "重装": "TANK",
    "狙击": "SNIPER",
    "术士": "CASTER",
    "医疗": "MEDIC",
    "辅助": "SUPPORT",
    "特种": "SPECIAL",
    "pioneer": "PIONEER",
    "warrior": "WARRIOR",
    "tank": "TANK",
    "sniper": "SNIPER",
    "caster": "CASTER",
    "medic": "MEDIC",
    "support": "SUPPORT",
    "special": "SPECIAL",
    "vanguard": "PIONEER",
    "guard": "WARRIOR",
    "defender": "TANK",
    "supporter": "SUPPORT",
    "specialist": "SPECIAL",
    "术师": "CASTER",
}


def translate_tool_men(tool_men: dict):
    standard = {}
    for name, count in tool_men.items():
        if name in profession_translation:
            standard_name = profession_translation[name]
            standard[standard_name] = count
        else:
            standard[name] = count
    return standard


def translate_drops(drops: list):
    for i in range(len(drops)):
        if drops[i] in profession_translation:
            drops[i] = profession_translation[drops[i]]
    return drops


def translate_strategy(strategy):
    strategy["tool_men"] = translate_tool_men(strategy["tool_men"])
    strategy["direction"] = translate_direction(strategy["direction"])
    return strategy


def translate_stage(stage):
    for i in range(len(stage["strategies"])):
        stage["strategies"][i] = translate_strategy(stage["strategies"][i])
    if "actions" in stage:
        stage["actions"] = translate_actions(stage["actions"])
    return stage


def pretranslate_sss(sss):
    sss["tool_men"] = translate_tool_men(sss["tool_men"])
    sss["drops"] = translate_drops(sss["drops"])
    for i in range(len(sss["stages"])):
        sss["stages"][i] = translate_stage(sss["stages"][i])
    return sss
