# DO NOT EDIT! This file is automatically generated
import marshmallow

from commercetools import helpers, types
from commercetools._schemas._common import BaseResourceSchema, ReferenceSchema

__all__ = [
    "CustomObjectDraftSchema",
    "CustomObjectPagedQueryResponseSchema",
    "CustomObjectReferenceSchema",
    "CustomObjectSchema",
]


class CustomObjectDraftSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.CustomObjectDraft`."""

    container = marshmallow.fields.String(allow_none=True)
    key = marshmallow.fields.String(allow_none=True)
    value = marshmallow.fields.Raw(allow_none=True)
    version = marshmallow.fields.Integer(allow_none=True, missing=None)

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.CustomObjectDraft(**data)


class CustomObjectPagedQueryResponseSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.CustomObjectPagedQueryResponse`."""

    limit = marshmallow.fields.Integer(allow_none=True)
    count = marshmallow.fields.Integer(allow_none=True)
    total = marshmallow.fields.Integer(allow_none=True, missing=None)
    offset = marshmallow.fields.Integer(allow_none=True)
    results = helpers.LazyNestedField(
        nested="commercetools._schemas._custom_object.CustomObjectSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        many=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.CustomObjectPagedQueryResponse(**data)


class CustomObjectReferenceSchema(ReferenceSchema):
    """Marshmallow schema for :class:`commercetools.types.CustomObjectReference`."""

    obj = helpers.LazyNestedField(
        nested="commercetools._schemas._custom_object.CustomObjectSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["type_id"]
        return types.CustomObjectReference(**data)


class CustomObjectSchema(BaseResourceSchema):
    """Marshmallow schema for :class:`commercetools.types.CustomObject`."""

    id = marshmallow.fields.String(allow_none=True)
    version = marshmallow.fields.Integer(allow_none=True)
    created_at = marshmallow.fields.DateTime(allow_none=True, data_key="createdAt")
    last_modified_at = marshmallow.fields.DateTime(
        allow_none=True, data_key="lastModifiedAt"
    )
    last_modified_by = helpers.LazyNestedField(
        nested="commercetools._schemas._common.LastModifiedBySchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
        data_key="lastModifiedBy",
    )
    created_by = helpers.LazyNestedField(
        nested="commercetools._schemas._common.CreatedBySchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
        data_key="createdBy",
    )
    container = marshmallow.fields.String(allow_none=True)
    key = marshmallow.fields.String(allow_none=True)
    value = marshmallow.fields.Raw(allow_none=True)

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.CustomObject(**data)
