# Path: esteid/constants.py
# class Countries:
#     """Mainly used by SmartID, also phone code"""
# 
#     ESTONIA = "EE"
#     LATVIA = "LV"
#     LITHUANIA = "LT"
# 
#     ALL = (ESTONIA, LATVIA, LITHUANIA)
# 
# Path: esteid/exceptions.py
# class InvalidIdCode(InvalidParameter):
#     """Invalid ID code (format or checksum don't match)"""
# 
#     default_message = _("Invalid ID code.")
# 
#     def __init__(self, message=None, *, param="id_code", **kwargs):
#         super().__init__(message, param=param, **kwargs)
# 
# class InvalidParameter(InvalidParameters):
#     """Invalid initialization parameter PARAM received from the request.
# 
#     Takes a `param` kwarg
#     """
# 
#     default_message = _("Invalid value for parameter {param}.")
# 
#     def __init__(self, message=None, *, param, **kwargs):
#         super().__init__(message)
#         self.kwargs = {**kwargs, "param": param}


import re
from esteid.constants import Countries
from esteid.exceptions import InvalidIdCode, InvalidParameter
    """
    if isinstance(id_code, str) and bool(re.match(ID_CODE_LV_REGEXP, id_code)):
        id_code = id_code.replace("-", "")
        factors = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
        checksum = (1101 - sum([i * int(d) for i, d in zip(factors, id_code[:10])])) % 11 % 10
        if int(id_code[-1]) == checksum:
            return True
    return False


# Lithuanian ID code format is the same as Estonian.
id_code_lt_is_valid = id_code_ee_is_valid


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 validate_id_code(id_code, country):
    try:
        validator = ID_CODE_VALIDATORS[country]
    except (KeyError, TypeError) as e:
        raise InvalidParameter(f"Unsupported country '{country}'", param="country") from e

    if not validator(id_code):
        # Find country name from Countries attributes
        cty = next(name for name, value in iter(Countries.__dict__.items()) if value == country)

# Path: esteid/constants.py
# class Countries:
#     """Mainly used by SmartID, also phone code"""
# 
#     ESTONIA = "EE"
#     LATVIA = "LV"
#     LITHUANIA = "LT"
# 
#     ALL = (ESTONIA, LATVIA, LITHUANIA)
# 
# Path: esteid/exceptions.py
# class InvalidIdCode(InvalidParameter):
#     """Invalid ID code (format or checksum don't match)"""
# 
#     default_message = _("Invalid ID code.")
# 
#     def __init__(self, message=None, *, param="id_code", **kwargs):
#         super().__init__(message, param=param, **kwargs)
# 
# class InvalidParameter(InvalidParameters):
#     """Invalid initialization parameter PARAM received from the request.
# 
#     Takes a `param` kwarg
#     """
# 
#     default_message = _("Invalid value for parameter {param}.")
# 
#     def __init__(self, message=None, *, param, **kwargs):
#         super().__init__(message)
#         self.kwargs = {**kwargs, "param": param}


# Path: esteid/validators.py
import re
from esteid.constants import Countries
from esteid.exceptions import InvalidIdCode, InvalidParameter

    """
    if isinstance(id_code, str) and bool(re.match(ID_CODE_LV_REGEXP, id_code)):
        id_code = id_code.replace("-", "")
        factors = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
        checksum = (1101 - sum([i * int(d) for i, d in zip(factors, id_code[:10])])) % 11 % 10
        if int(id_code[-1]) == checksum:
            return True
    return False


# Lithuanian ID code format is the same as Estonian.
id_code_lt_is_valid = id_code_ee_is_valid


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 validate_id_code(id_code, country):
    try:
        validator = ID_CODE_VALIDATORS[country]
    except (KeyError, TypeError) as e:
        raise InvalidParameter(f"Unsupported country '{country}'", param="country") from e

    if not validator(id_code):
        # Find country name from Countries attributes
        cty = next(name for name, value in iter(Countries.__dict__.items()) if value == country)

        raise InvalidIdCode(f"ID code '{id_code}' is not valid for {cty.capitalize()}")