# Path: esteid/mobileid/utils.py
# def get_verification_code(hash_value):
#     """Compute Mobile-ID verification code from a hash
# 
#     Excerpt from https://github.com/SK-EID/MID#241-verification-code-calculation-algorithm
# 
#     1. 6 bits from the beginning of hash and 7 bits from the end of hash are taken.
#     2. The resulting 13 bits are transformed into decimal number and printed out.
# 
#     The Verification code is a decimal 4-digits number in range 0000...8192, always 4 digits are displayed (e.g. 0041).
# 
#     :param bytes hash_value:
#     """
#     if not isinstance(hash_value, bytes):
#         raise TypeError(f"Invalid hash value: expected bytes, got {type(hash_value)}")
# 
#     if not hash_value:
#         raise ValueError("Hash value can not be empty")
# 
#     leading_byte = hash_value[0]
#     trailing_byte = hash_value[-1]
# 
#     leading_6_bits = leading_byte >> 2
#     trailing_7_bits = trailing_byte & 0x7F
# 
#     raw_value = (leading_6_bits << 7) + trailing_7_bits
#     return f"{raw_value:04d}"


import hashlib
import pytest
from ..utils import get_verification_code




@pytest.mark.parametrize(
    "hash_value,expected_verification_code",
    [
        (b"\x00\x00", "0000"),
        (b"00", "1584"),
        (hashlib.sha256(b"test").digest(), "5000"),
        (hashlib.sha512(b"test").digest(), "7679"),
    ],
)
def test_mobileid_get_verification_code(expected_verification_code, hash_value):

# Path: esteid/mobileid/utils.py
# def get_verification_code(hash_value):
#     """Compute Mobile-ID verification code from a hash
# 
#     Excerpt from https://github.com/SK-EID/MID#241-verification-code-calculation-algorithm
# 
#     1. 6 bits from the beginning of hash and 7 bits from the end of hash are taken.
#     2. The resulting 13 bits are transformed into decimal number and printed out.
# 
#     The Verification code is a decimal 4-digits number in range 0000...8192, always 4 digits are displayed (e.g. 0041).
# 
#     :param bytes hash_value:
#     """
#     if not isinstance(hash_value, bytes):
#         raise TypeError(f"Invalid hash value: expected bytes, got {type(hash_value)}")
# 
#     if not hash_value:
#         raise ValueError("Hash value can not be empty")
# 
#     leading_byte = hash_value[0]
#     trailing_byte = hash_value[-1]
# 
#     leading_6_bits = leading_byte >> 2
#     trailing_7_bits = trailing_byte & 0x7F
# 
#     raw_value = (leading_6_bits << 7) + trailing_7_bits
#     return f"{raw_value:04d}"


# Path: esteid/mobileid/tests/test_utils.py
import hashlib
import pytest
from ..utils import get_verification_code





@pytest.mark.parametrize(
    "hash_value,expected_verification_code",
    [
        (b"\x00\x00", "0000"),
        (b"00", "1584"),
        (hashlib.sha256(b"test").digest(), "5000"),
        (hashlib.sha512(b"test").digest(), "7679"),
    ],
)
def test_mobileid_get_verification_code(expected_verification_code, hash_value):

    assert get_verification_code(hash_value) == expected_verification_code