from .query import QuerySet

class Manager:
    def __init__(self):
        self.model_cls = None  # will be set automatically
 

    def __get__(self, instance, owner):
        # owner = the actual model class (Book, User, etc.)
        if self.model_cls is None:
            self.model_cls = owner
        return self

    def create(self, **kwargs):
        if self.model_cls is None:
            raise RuntimeError("Manager not bound to a model class")
        instance = self.model_cls(**kwargs)
        instance.save()
        return instance

    def all(self):
        if self.model_cls is None:
            raise RuntimeError("Manager not bound to a model class")
        return QuerySet(self.model_cls)
 
    def filter(self, **kwargs):
        return QuerySet(self.model_cls).filter(**kwargs)

    def get(self, **kwargs):
        return QuerySet(self.model_cls).get(**kwargs)

