from typing import Tuple
from typing import Optional


def split_package_build_string(build_string: str) -> Tuple[str, Optional[int]]:
    """Helper method for parsing build_string.

    Returns:
        Tuple (build_string, build_number)
    """

    if '' == build_string:
        return '', None

    if build_string.isdigit():
        return '', int(build_string)

    _pos = build_string.rindex('_') if '_' in build_string else -1
    if _pos >= 1:
        # Build number will be the last part - check if it's an integer
        # Updated logic given https://github.com/CycloneDX/cyclonedx-python-lib/issues/65
        build_number = build_string[_pos + 1:]
        if build_number.isdigit():
            return build_string, int(build_number)

    return build_string, None