# Path: lib/Utility.py
# RE_COMPILED_TYPE = type(re.compile(''))


import copy
import re
from enum import Enum
from lib.Utility import RE_COMPILED_TYPE
#     'crafted': ModFilterType.Crafted,
#     'prophecy': ModFilterType.Prophecy,
#     'leaguestone': ModFilterType.Leaguestone
# }
#
# _typeToName = dict(reversed(item) for item in _nameToType.items())

class ModFilter:
    __slots__ = ['type', 'expr', 'min', 'max']

    def __init__(self, mod_type=ModFilterType.Total, expr='', min_val=None, max_val=None):
        self.type = mod_type
        self.expr = expr
        self.min = float(min_val) if min_val is not None else min_val
        self.max = float(max_val) if max_val is not None else max_val

    @classmethod
    def fromData(cls, data):
        return cls(ModFilterType(data['type']), data['expr'], data.get('min', None), data.get('max', None))

    def toDict(self):
        return {
            'type': self.type.value,
            'expr': self.expr,
            'min': self.min,
            'max': self.max
        }

    def __deepcopy__(self, memo):
        cls = self.__class__

# Path: lib/Utility.py
# RE_COMPILED_TYPE = type(re.compile(''))


# Path: lib/ModFilter.py
import copy
import re
from enum import Enum
from lib.Utility import RE_COMPILED_TYPE

#     'crafted': ModFilterType.Crafted,
#     'prophecy': ModFilterType.Prophecy,
#     'leaguestone': ModFilterType.Leaguestone
# }
#
# _typeToName = dict(reversed(item) for item in _nameToType.items())

class ModFilter:
    __slots__ = ['type', 'expr', 'min', 'max']

    def __init__(self, mod_type=ModFilterType.Total, expr='', min_val=None, max_val=None):
        self.type = mod_type
        self.expr = expr
        self.min = float(min_val) if min_val is not None else min_val
        self.max = float(max_val) if max_val is not None else max_val

    @classmethod
    def fromData(cls, data):
        return cls(ModFilterType(data['type']), data['expr'], data.get('min', None), data.get('max', None))

    def toDict(self):
        return {
            'type': self.type.value,
            'expr': self.expr,
            'min': self.min,
            'max': self.max
        }

    def __deepcopy__(self, memo):
        cls = self.__class__

        result = cls.__new__(cls)