# Path: esteid/constants.py
# HASH_ALGORITHMS = {
#     HASH_SHA256,
#     HASH_SHA384,
#     HASH_SHA512,
# }
# 
# Path: esteid/util.py
# def generate_hash(algorithm, data):
#     """Hash the data with the supplied algorithm
# 
#     https://github.com/SK-EID/smart-id-documentation#33-hash-algorithms
#     https://github.com/SK-EID/MID#231-supported-hashing-algorithms
#     """
#     if algorithm.upper() not in HASH_ALGORITHMS:
#         raise ValueError(f"Unsupported algorithm {algorithm}")
# 
#     hash_method = getattr(hashlib, algorithm.lower())
#     digest = hash_method(data).digest()
# 
#     return digest
# 
# Path: esteid/validators.py
# ID_CODE_EE_REGEXP = re.compile(r"^[1-6] \d{2} [01]\d [0123]\d \d{4}$", re.VERBOSE)
# ID_CODE_LT_REGEXP = ID_CODE_EE_REGEXP
# ID_CODE_LV_REGEXP = re.compile(r"^\d{6}-\d{5}$")
# ID_CODE_VALIDATORS = {
#     Countries.ESTONIA: id_code_ee_is_valid,
#     Countries.LATVIA: id_code_lv_is_valid,
#     Countries.LITHUANIA: id_code_lt_is_valid,
# }
# def id_code_ee_is_valid(id_code: str) -> bool:
# def id_code_lv_is_valid(id_code: str) -> bool:
# def validate_id_code(id_code, country):


import hashlib
import pytest
from esteid.constants import HASH_ALGORITHMS
from esteid.util import generate_hash
from esteid.validators import id_code_ee_is_valid, id_code_lt_is_valid, id_code_lv_is_valid
@pytest.mark.parametrize("hash_algo", HASH_ALGORITHMS)
def test_hashtypes(hash_algo):
    hash_value = generate_hash(hash_algo, b"FOOBAR")

    hash_method = getattr(hashlib, hash_algo.lower())
    assert hash_value == hash_method(b"FOOBAR").digest()


def test_invalid_hash_algo_fails():
    with pytest.raises(ValueError):
        generate_hash("FAKEHASH", b"FOOBAR")


@pytest.mark.parametrize(
    "id_code, result",
    [
        pytest.param("", False, id="empty string"),
        pytest.param(None, False, id="None"),
        pytest.param(["30303039914"], False, id="list"),
        pytest.param("ABCDEFGHQWE", False, id="not digits"),
        pytest.param("10101010", False, id="not enough digits"),
        pytest.param("10101010OO5", False, id="not all digits (0-O)"),
        pytest.param("123456789O123456", False, id="too many digits"),
        pytest.param("10101010101", False, id="wrong checksum"),
        pytest.param("30303039914", True, id="test SmartID code"),
        pytest.param("60001019906", True, id="test MobileID code"),
        pytest.param("37605030299", True, id="From Wikipedia"),
    ],
)
def test_id_code_ee_lt_is_valid(id_code, result):

# Path: esteid/constants.py
# HASH_ALGORITHMS = {
#     HASH_SHA256,
#     HASH_SHA384,
#     HASH_SHA512,
# }
# 
# Path: esteid/util.py
# def generate_hash(algorithm, data):
#     """Hash the data with the supplied algorithm
# 
#     https://github.com/SK-EID/smart-id-documentation#33-hash-algorithms
#     https://github.com/SK-EID/MID#231-supported-hashing-algorithms
#     """
#     if algorithm.upper() not in HASH_ALGORITHMS:
#         raise ValueError(f"Unsupported algorithm {algorithm}")
# 
#     hash_method = getattr(hashlib, algorithm.lower())
#     digest = hash_method(data).digest()
# 
#     return digest
# 
# Path: esteid/validators.py
# ID_CODE_EE_REGEXP = re.compile(r"^[1-6] \d{2} [01]\d [0123]\d \d{4}$", re.VERBOSE)
# ID_CODE_LT_REGEXP = ID_CODE_EE_REGEXP
# ID_CODE_LV_REGEXP = re.compile(r"^\d{6}-\d{5}$")
# ID_CODE_VALIDATORS = {
#     Countries.ESTONIA: id_code_ee_is_valid,
#     Countries.LATVIA: id_code_lv_is_valid,
#     Countries.LITHUANIA: id_code_lt_is_valid,
# }
# def id_code_ee_is_valid(id_code: str) -> bool:
# def id_code_lv_is_valid(id_code: str) -> bool:
# def validate_id_code(id_code, country):


# Path: esteid/tests/test_utils.py
import hashlib
import pytest
from esteid.constants import HASH_ALGORITHMS
from esteid.util import generate_hash
from esteid.validators import id_code_ee_is_valid, id_code_lt_is_valid, id_code_lv_is_valid

@pytest.mark.parametrize("hash_algo", HASH_ALGORITHMS)
def test_hashtypes(hash_algo):
    hash_value = generate_hash(hash_algo, b"FOOBAR")

    hash_method = getattr(hashlib, hash_algo.lower())
    assert hash_value == hash_method(b"FOOBAR").digest()


def test_invalid_hash_algo_fails():
    with pytest.raises(ValueError):
        generate_hash("FAKEHASH", b"FOOBAR")


@pytest.mark.parametrize(
    "id_code, result",
    [
        pytest.param("", False, id="empty string"),
        pytest.param(None, False, id="None"),
        pytest.param(["30303039914"], False, id="list"),
        pytest.param("ABCDEFGHQWE", False, id="not digits"),
        pytest.param("10101010", False, id="not enough digits"),
        pytest.param("10101010OO5", False, id="not all digits (0-O)"),
        pytest.param("123456789O123456", False, id="too many digits"),
        pytest.param("10101010101", False, id="wrong checksum"),
        pytest.param("30303039914", True, id="test SmartID code"),
        pytest.param("60001019906", True, id="test MobileID code"),
        pytest.param("37605030299", True, id="From Wikipedia"),
    ],
)
def test_id_code_ee_lt_is_valid(id_code, result):

    assert id_code_ee_is_valid(id_code) == result