# Path: beavy/common/paging_schema.py
# def makePaginationSchema(itemsCls, field_cls=fields.Nested):
#     return type("{}Paging".format(itemsCls.__class__.__name__),
#                 (BasePaging, ), dict(items=field_cls(itemsCls, many=True)))
# 
# Path: beavy/common/morphing_schema.py
# class MorphingSchema():
# 
#     @pre_dump
#     def select_processor(self, obj, many=False,
#                          strict=False, update_fields=False):
#         if many:
#             return [self._get_serializer(item) for item in obj]
#         return self._get_serializer(obj)
# 
#     def _obj_to_name(self, obj):
#         return obj.__mapper__.polymorphic_identity
# 
#     def _get_serializer(self, obj):
#         name = self._obj_to_name(obj)
#         return self.registry.get(name, self.FALLBACK)()
# 
# Path: beavy/schemas/user.py
# class BaseUser(Schema):
#     class Meta:
#         type_ = "user"
# 
#     id = fields.Function(lambda obj: obj.__LOOKUP_ATTRS__ and
#                          getattr(obj, obj.__LOOKUP_ATTRS__[0]) or
#                          obj.id)
#     beavyId = fields.Integer(attribute="id")
#     name = fields.String()
#     active = fields.Boolean()
#     created_at = fields.DateTime()
#     language_preference = fields.String()


from beavy.common.paging_schema import makePaginationSchema
from beavy.common.morphing_schema import MorphingSchema
from marshmallow_jsonapi import Schema, fields
from .user import BaseUser



class BaseObject(Schema):
    class Meta:
        type_ = "object"

    id = fields.Integer()
    created_at = fields.DateTime()
    owner = fields.Nested(BaseUser)
    belongs_to_id = fields.Integer()  # don't leak
    type = fields.String(attribute="discriminator")


class ObjectField(MorphingSchema):
    FALLBACK = BaseObject
    registry = {}


class ObjectSchema(ObjectField, Schema):
    pass



# Path: beavy/common/paging_schema.py
# def makePaginationSchema(itemsCls, field_cls=fields.Nested):
#     return type("{}Paging".format(itemsCls.__class__.__name__),
#                 (BasePaging, ), dict(items=field_cls(itemsCls, many=True)))
# 
# Path: beavy/common/morphing_schema.py
# class MorphingSchema():
# 
#     @pre_dump
#     def select_processor(self, obj, many=False,
#                          strict=False, update_fields=False):
#         if many:
#             return [self._get_serializer(item) for item in obj]
#         return self._get_serializer(obj)
# 
#     def _obj_to_name(self, obj):
#         return obj.__mapper__.polymorphic_identity
# 
#     def _get_serializer(self, obj):
#         name = self._obj_to_name(obj)
#         return self.registry.get(name, self.FALLBACK)()
# 
# Path: beavy/schemas/user.py
# class BaseUser(Schema):
#     class Meta:
#         type_ = "user"
# 
#     id = fields.Function(lambda obj: obj.__LOOKUP_ATTRS__ and
#                          getattr(obj, obj.__LOOKUP_ATTRS__[0]) or
#                          obj.id)
#     beavyId = fields.Integer(attribute="id")
#     name = fields.String()
#     active = fields.Boolean()
#     created_at = fields.DateTime()
#     language_preference = fields.String()


# Path: beavy/schemas/object.py
from beavy.common.paging_schema import makePaginationSchema
from beavy.common.morphing_schema import MorphingSchema
from marshmallow_jsonapi import Schema, fields
from .user import BaseUser




class BaseObject(Schema):
    class Meta:
        type_ = "object"

    id = fields.Integer()
    created_at = fields.DateTime()
    owner = fields.Nested(BaseUser)
    belongs_to_id = fields.Integer()  # don't leak
    type = fields.String(attribute="discriminator")


class ObjectField(MorphingSchema):
    FALLBACK = BaseObject
    registry = {}


class ObjectSchema(ObjectField, Schema):
    pass



objects_paged = makePaginationSchema(ObjectSchema)()