# Path: cdrouter/cdr_datetime.py
# class DateTime(fields.DateTime):
#     def __init__(self, format=None, **kwargs):
#         super(DateTime, self).__init__(format=format, **kwargs)
#         
#     def _serialize(self, value, attr, obj):
#         try:
#             return super(DateTime, self)._serialize(value, attr, obj)
#         except ValidationError:
#             return datetime.min
# 
#     def _deserialize(self, value, attr, data):
#         try:
#             return super(DateTime, self)._deserialize(value, attr, data)
#         except ValidationError:
#             return datetime.min
# 
# Path: cdrouter/cdr_dictfield.py
# class DictField(fields.Field):
#     def __init__(self, key_field, nested_field, *args, **kwargs):
#         super(DictField, self).__init__(self, *args, **kwargs)
#         self.key_field = key_field
#         self.nested_field = nested_field
# 
#     def _deserialize(self, value, attr, data):
#         if not isinstance(value, collections.Mapping):
#             self.fail('invalid')
# 
#         ret = {}
#         for key, val in value.items():
#             k = self.key_field._deserialize(key, attr, data)
#             data, errors = self.nested_field.load(val)
#             if errors:
#                 raise ValidationError(errors, data=data)
#             v = data
#             ret[k] = v
# 
#         return ret
# 
#     def _serialize(self, value, attr, obj):
#         ret = {}
#         for key, val in value.items():
#             k = self.key_field._serialize(key, attr, obj)
#             data, errors = self.nested_field.dump(val)
#             if errors:
#                 raise ValidationError(errors, data=data)
#             v = data
#             ret[k] = v
#         return ret


import os.path
from marshmallow import Schema, fields, post_load
from .cdr_datetime import DateTime
from .cdr_dictfield import DictField
    existing_id = fields.Int(as_string=True, missing=None)
    response = fields.Nested(ResponseSchema, missing=None)

    @post_load
    def post_load(self, data):
        return Resource(**data)

class Request(object):
    """Model for CDRouter Import Requests.

    :param replace_existing: (optional) Bool `True` if existing resources should be overwritten.
    :param configs: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param devices: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param packages: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param results: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param tags: (optional) Tags to add to imported resources as string list.
    """
    def __init__(self, **kwargs):
        self.replace_existing = kwargs.get('replace_existing', None)

        self.configs = kwargs.get('configs', None)
        self.devices = kwargs.get('devices', None)
        self.packages = kwargs.get('packages', None)
        self.results = kwargs.get('results', None)

        self.tags = kwargs.get('tags', None)

class RequestSchema(Schema):
    replace_existing = fields.Bool()


# Path: cdrouter/cdr_datetime.py
# class DateTime(fields.DateTime):
#     def __init__(self, format=None, **kwargs):
#         super(DateTime, self).__init__(format=format, **kwargs)
#         
#     def _serialize(self, value, attr, obj):
#         try:
#             return super(DateTime, self)._serialize(value, attr, obj)
#         except ValidationError:
#             return datetime.min
# 
#     def _deserialize(self, value, attr, data):
#         try:
#             return super(DateTime, self)._deserialize(value, attr, data)
#         except ValidationError:
#             return datetime.min
# 
# Path: cdrouter/cdr_dictfield.py
# class DictField(fields.Field):
#     def __init__(self, key_field, nested_field, *args, **kwargs):
#         super(DictField, self).__init__(self, *args, **kwargs)
#         self.key_field = key_field
#         self.nested_field = nested_field
# 
#     def _deserialize(self, value, attr, data):
#         if not isinstance(value, collections.Mapping):
#             self.fail('invalid')
# 
#         ret = {}
#         for key, val in value.items():
#             k = self.key_field._deserialize(key, attr, data)
#             data, errors = self.nested_field.load(val)
#             if errors:
#                 raise ValidationError(errors, data=data)
#             v = data
#             ret[k] = v
# 
#         return ret
# 
#     def _serialize(self, value, attr, obj):
#         ret = {}
#         for key, val in value.items():
#             k = self.key_field._serialize(key, attr, obj)
#             data, errors = self.nested_field.dump(val)
#             if errors:
#                 raise ValidationError(errors, data=data)
#             v = data
#             ret[k] = v
#         return ret


# Path: cdrouter/imports.py
import os.path
from marshmallow import Schema, fields, post_load
from .cdr_datetime import DateTime
from .cdr_dictfield import DictField

    existing_id = fields.Int(as_string=True, missing=None)
    response = fields.Nested(ResponseSchema, missing=None)

    @post_load
    def post_load(self, data):
        return Resource(**data)

class Request(object):
    """Model for CDRouter Import Requests.

    :param replace_existing: (optional) Bool `True` if existing resources should be overwritten.
    :param configs: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param devices: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param packages: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param results: (optional) Dict of strings to :class:`imports.Resource <imports.Resource>` objects.
    :param tags: (optional) Tags to add to imported resources as string list.
    """
    def __init__(self, **kwargs):
        self.replace_existing = kwargs.get('replace_existing', None)

        self.configs = kwargs.get('configs', None)
        self.devices = kwargs.get('devices', None)
        self.packages = kwargs.get('packages', None)
        self.results = kwargs.get('results', None)

        self.tags = kwargs.get('tags', None)

class RequestSchema(Schema):
    replace_existing = fields.Bool()


    configs = DictField(fields.Str(), ResourceSchema())