from django.conf import settings
from hashids import Hashids


class CFHashIds:
    def __init__(self):
        self.hashids_instance = Hashids(salt=settings.HASHID_SECRET, min_length=20,
                                        alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')

    def encode(self, value):
        return self.hashids_instance.encode(value)

    def decode(self, value):
        decoded_values = self.hashids_instance.decode(value)
        if decoded_values:
            return decoded_values[0]

        return None
