def calculate_check_digit(nhs_number: str) -> int:
    """Given a nine-digit NHS Number calculate the tenth check digit."""

    if not nhs_number.isdigit():
        raise ValueError("nhs_number must comprise only digits")
    if len(nhs_number) != 9:
        raise ValueError("Expecting nine digits")

    # https://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp?shownav=1
    digits_weighted = [int(v) for v in list(nhs_number)]
    for i in range(9):
        digits_weighted[i] = digits_weighted[i] * (10 - i)
    check_digit = 11 - (sum(digits_weighted) % 11)
    if check_digit == 11:
        check_digit = 0

    if check_digit == 10:
        raise ValueError("Number is invalid")

    return check_digit