# parser.py


# def parse_region_id(host: str) -> int | None:
#     """
#     Извлекает region_id из строки host.
#     Формат: p<region><...>, например p18ecpapp01 → region_id = 18
#
#     Returns:
#         int | None: номер региона или None
#     """
#     if not host or not host.startswith("p"):
#         return None
#
#     match = re.match(r"^p(\d+)", host)
#     if match:
#         return int(match.group(1))
#     return None

def parse_region_id(hostgroups: str | None) -> str:
    if not hostgroups:
        return "0"

    if hostgroups == "p00rtmis":
        return "0"

    parts = hostgroups.split("_")
    if len(parts) >= 2:
        return parts[1]

    return "0"
