# Path: src/pyoffers/utils.py
# class Filter(dict):
#     """Custom subtype to apply special behaviour."""
# 
#     def __init__(self, connector="AND", **kwargs):
#         self.connector = connector
#         super().__init__(**kwargs)
# 
# class Sort(list):
#     """Handles sort queries."""
# 
#     def __init__(self, args, model):
#         if not isinstance(args, (list, tuple, set)):
#             args = [args]
#         super().__init__([self.prepend_model(value, model) for value in args])
# 
#     def prepend_model(self, value, model):
#         """Prepends model name if it is not already prepended.
# 
#         For example model is "Offer":
# 
#             key -> Offer.key
#             -key -> -Offer.key
#             Offer.key -> Offer.key
#             -Offer.key -> -Offer.key
#         """
#         if "." not in value:
#             direction = ""
#             if value.startswith("-"):
#                 value = value[1:]
#                 direction = "-"
#             value = "{}{}.{}".format(direction, model, value)
#         return value


from collections import defaultdict
from ..utils import Filter, Sort
    def update(self, id, **kwargs):
        return self._call("update", id=id, data=kwargs)

    @generic_method
    def delete(self, id):
        return self.update(id=id, status="deleted")

    @generic_method
    def find_by_id(self, id, fields=None, contain=None):
        assert fields is None or isinstance(fields, (tuple, list)), "Fields should be a tuple or list"
        return self._call("findById", id=id, fields=fields, contain=contain)

    @generic_method
    def find_all(self, sort=(), limit=None, page=None, fields=None, contain=None, **kwargs):
        assert limit is None or isinstance(limit, int), "Limit should be an integer"
        assert page is None or isinstance(page, int), "Page should be an integer"
        assert fields is None or isinstance(fields, (tuple, list)), "Fields should be a tuple or list"
        return self._call(
            "findAll",
            filters=Filter(**kwargs),
            sort=Sort(sort, self.model.__name__),
            limit=limit,
            page=page,
            fields=fields,
            contain=contain,
            single_result=False,
        )

    @generic_method
    def find_all_ids(self, **kwargs):

# Path: src/pyoffers/utils.py
# class Filter(dict):
#     """Custom subtype to apply special behaviour."""
# 
#     def __init__(self, connector="AND", **kwargs):
#         self.connector = connector
#         super().__init__(**kwargs)
# 
# class Sort(list):
#     """Handles sort queries."""
# 
#     def __init__(self, args, model):
#         if not isinstance(args, (list, tuple, set)):
#             args = [args]
#         super().__init__([self.prepend_model(value, model) for value in args])
# 
#     def prepend_model(self, value, model):
#         """Prepends model name if it is not already prepended.
# 
#         For example model is "Offer":
# 
#             key -> Offer.key
#             -key -> -Offer.key
#             Offer.key -> Offer.key
#             -Offer.key -> -Offer.key
#         """
#         if "." not in value:
#             direction = ""
#             if value.startswith("-"):
#                 value = value[1:]
#                 direction = "-"
#             value = "{}{}.{}".format(direction, model, value)
#         return value


# Path: src/pyoffers/models/core.py
from collections import defaultdict
from ..utils import Filter, Sort

    def update(self, id, **kwargs):
        return self._call("update", id=id, data=kwargs)

    @generic_method
    def delete(self, id):
        return self.update(id=id, status="deleted")

    @generic_method
    def find_by_id(self, id, fields=None, contain=None):
        assert fields is None or isinstance(fields, (tuple, list)), "Fields should be a tuple or list"
        return self._call("findById", id=id, fields=fields, contain=contain)

    @generic_method
    def find_all(self, sort=(), limit=None, page=None, fields=None, contain=None, **kwargs):
        assert limit is None or isinstance(limit, int), "Limit should be an integer"
        assert page is None or isinstance(page, int), "Page should be an integer"
        assert fields is None or isinstance(fields, (tuple, list)), "Fields should be a tuple or list"
        return self._call(
            "findAll",
            filters=Filter(**kwargs),
            sort=Sort(sort, self.model.__name__),
            limit=limit,
            page=page,
            fields=fields,
            contain=contain,
            single_result=False,
        )

    @generic_method
    def find_all_ids(self, **kwargs):

        return self._call("findAllIds", filters=Filter(**kwargs), single_result=False, raw=True)