# Path: rmr/utils/hash.py
# def crc64(string, make_crc64=crcmod.predefined.mkPredefinedCrcFun('crc-64')):
#     crc = make_crc64(bytes(string, encoding='utf-8'))
#     if crc > 9223372036854775807:  # 2 ** 64 // 2 - 1
#         crc = -(crc >> 1)
#     return crc


import warnings
from django.db import models
from rmr.utils.hash import crc64




class HashLookup(models.BigIntegerField):

    def __init__(self, *args, object_field, **kwargs):
        warnings.warn(
            'HashLookup is deprecated and will be removed in rmr-django 2.0',
            DeprecationWarning,
        )
        self.object_field = object_field
        super().__init__(*args, **kwargs)

    def deconstruct(self):
        name, path, args, kwargs = super().deconstruct()
        kwargs['object_field'] = self.object_field
        return name, path, args, kwargs

    def pre_save(self, model_instance, add):
        obj = getattr(model_instance, self.object_field)
        return None if obj is None else crc64(obj)

    def get_prep_lookup(self, lookup_type, value):

# Path: rmr/utils/hash.py
# def crc64(string, make_crc64=crcmod.predefined.mkPredefinedCrcFun('crc-64')):
#     crc = make_crc64(bytes(string, encoding='utf-8'))
#     if crc > 9223372036854775807:  # 2 ** 64 // 2 - 1
#         crc = -(crc >> 1)
#     return crc


# Path: rmr/models/fields/hash_lookup.py
import warnings
from django.db import models
from rmr.utils.hash import crc64





class HashLookup(models.BigIntegerField):

    def __init__(self, *args, object_field, **kwargs):
        warnings.warn(
            'HashLookup is deprecated and will be removed in rmr-django 2.0',
            DeprecationWarning,
        )
        self.object_field = object_field
        super().__init__(*args, **kwargs)

    def deconstruct(self):
        name, path, args, kwargs = super().deconstruct()
        kwargs['object_field'] = self.object_field
        return name, path, args, kwargs

    def pre_save(self, model_instance, add):
        obj = getattr(model_instance, self.object_field)
        return None if obj is None else crc64(obj)

    def get_prep_lookup(self, lookup_type, value):

        return crc64(value)