from typing import List


data = {
    "groups": [
        {
            "id": "0193da9f-230e-783c-a372-6de37d9bc618",
            "name": "Global",
            "description": "",
            "subgroups": [
                {
                    "id": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3",
                    "name": "Москва",
                    "description": "",
                    "parentId": "0193da9f-230e-783c-a372-6de37d9bc618",
                    "subgroups": [
                        {
                            "id": "0193f837-3821-7dbc-a7c9-9d2029de4a15",
                            "name": "СПБ",
                            "description": "",
                            "parentId": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3",
                            "subgroups": [],
                        }
                    ],
                }
            ],
        },
        {
            "id": "0193da9f-230e-783c-a372-6de37d9bc618_2",
            "name": "Global",
            "description": "",
            "subgroups": [
                {
                    "id": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3_2",
                    "name": "Москва",
                    "description": "",
                    "parentId": "0193da9f-230e-783c-a372-6de37d9bc618_2",
                    "subgroups": [
                        {
                            "id": "0193f837-3821-7dbc-a7c9-9d2029de4a15_2",
                            "name": "СПБ",
                            "description": "",
                            "parentId": "0193f836-f7f9-74a6-8192-3e4f2f67f7e3_2",
                            "subgroups": [],
                        }
                    ],
                }
            ],
        },
    ]
}


def parse_subgroups(list_of_id: List, subgroups: List):
    if not subgroups:
        return
    for group in subgroups:
        list_of_id.append(group["id"])
        parse_subgroups(list_of_id, group["subgroups"])


def list_all_group_ids(groups_list: List) -> List:
    result = []
    if not groups_list:
        return result
    for group_entry in groups_list:
        result.append(group_entry["id"])
        parse_subgroups(result, group_entry["subgroups"])
    return result


print(list_all_group_ids(data["groups"]))
