# Path: typepy/_common.py
# def remove_thousand_sep(value: str) -> str:
#     if REGEXP_THOUSAND_SEP.search(value) is None:
#         return value
# 
#     return value.replace(",", "")
# 
# def strip_ansi_escape(value: Any) -> str:
#     return ansi_escape.sub("", value)
# 
# Path: typepy/_const.py
# class DefaultValue:
#     FLOAT_TYPE = Decimal
#     STRIP_ANSI_ESCAPE = True
# 
# class ParamKey:
#     STRIP_ANSI_ESCAPE = "strip_ansi_escape"
#     TIMEZONE = "timezone"
# 
# Path: typepy/error.py
# class TypeConversionError(TypeError):
#     """
#     Exception raised when failed to convert data.
#     """
# 
# Path: typepy/converter/_interface.py
# class AbstractValueConverter(ValueConverterInterface):
#     __slots__ = "_value"
# 
#     def __init__(self, value, params):
#         self._value = value
#         self._params = params
# 
#     def __repr__(self):
#         try:
#             string = str(self.force_convert())
#         except TypeConversionError:
#             string = "[ValueConverter ERROR] failed to force_convert"
# 
#         return string


from decimal import Decimal, InvalidOperation
from .._common import remove_thousand_sep, strip_ansi_escape
from .._const import DefaultValue, ParamKey
from ..error import TypeConversionError
from ._interface import AbstractValueConverter
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""




class IntegerConverter(AbstractValueConverter):
    def force_convert(self):
        try:
            value = remove_thousand_sep(self._value)
        except TypeError:
            value = self._value

        try:
            return int(Decimal(value))
        except (TypeError, OverflowError, ValueError, InvalidOperation):
            pass

        if self._params.get(ParamKey.STRIP_ANSI_ESCAPE, DefaultValue.STRIP_ANSI_ESCAPE):
            try:
                return int(Decimal(strip_ansi_escape(value)))
            except (TypeError, OverflowError, ValueError, InvalidOperation):
                pass


# Path: typepy/_common.py
# def remove_thousand_sep(value: str) -> str:
#     if REGEXP_THOUSAND_SEP.search(value) is None:
#         return value
# 
#     return value.replace(",", "")
# 
# def strip_ansi_escape(value: Any) -> str:
#     return ansi_escape.sub("", value)
# 
# Path: typepy/_const.py
# class DefaultValue:
#     FLOAT_TYPE = Decimal
#     STRIP_ANSI_ESCAPE = True
# 
# class ParamKey:
#     STRIP_ANSI_ESCAPE = "strip_ansi_escape"
#     TIMEZONE = "timezone"
# 
# Path: typepy/error.py
# class TypeConversionError(TypeError):
#     """
#     Exception raised when failed to convert data.
#     """
# 
# Path: typepy/converter/_interface.py
# class AbstractValueConverter(ValueConverterInterface):
#     __slots__ = "_value"
# 
#     def __init__(self, value, params):
#         self._value = value
#         self._params = params
# 
#     def __repr__(self):
#         try:
#             string = str(self.force_convert())
#         except TypeConversionError:
#             string = "[ValueConverter ERROR] failed to force_convert"
# 
#         return string


# Path: typepy/converter/_integer.py
from decimal import Decimal, InvalidOperation
from .._common import remove_thousand_sep, strip_ansi_escape
from .._const import DefaultValue, ParamKey
from ..error import TypeConversionError
from ._interface import AbstractValueConverter

"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""




class IntegerConverter(AbstractValueConverter):
    def force_convert(self):
        try:
            value = remove_thousand_sep(self._value)
        except TypeError:
            value = self._value

        try:
            return int(Decimal(value))
        except (TypeError, OverflowError, ValueError, InvalidOperation):
            pass

        if self._params.get(ParamKey.STRIP_ANSI_ESCAPE, DefaultValue.STRIP_ANSI_ESCAPE):
            try:
                return int(Decimal(strip_ansi_escape(value)))
            except (TypeError, OverflowError, ValueError, InvalidOperation):
                pass


        raise TypeConversionError(f"failed to force_convert to int: type={type(value)}")