# 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
"""Module for accessing CDRouter Imports."""


class Import(object):
    """Model for CDRouter Staged Imports.

    :param id: (optional) Staged import ID as an int.
    :param user_id: (optional) User ID as an int.
    :param created: (optional) Creation time as `DateTime`.
    :param updated: (optional) Last-updated time as `DateTime`.
    :param archive: (optional) Path to archive as string.
    :param path: (optional) Local filepath as string.
    :param url: (optional) URL to fetch as string.
    :param insecure: (optional) Allow insecure HTTPS connections if bool `True`.
    :param size: (optional) Size of import as int.
    """
    def __init__(self, **kwargs):
        self.id = kwargs.get('id', None)
        self.user_id = kwargs.get('user_id', None)
        self.created = kwargs.get('created', None)
        self.updated = kwargs.get('updated', None)
        self.archive = kwargs.get('archive', None)
        self.path = kwargs.get('path', None)
        self.url = kwargs.get('url', None)
        self.insecure = kwargs.get('insecure', None)
        self.size = kwargs.get('size', None)

class ImportSchema(Schema):
    id = fields.Int(as_string=True)
    user_id = fields.Int(as_string=True)

# 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

"""Module for accessing CDRouter Imports."""


class Import(object):
    """Model for CDRouter Staged Imports.

    :param id: (optional) Staged import ID as an int.
    :param user_id: (optional) User ID as an int.
    :param created: (optional) Creation time as `DateTime`.
    :param updated: (optional) Last-updated time as `DateTime`.
    :param archive: (optional) Path to archive as string.
    :param path: (optional) Local filepath as string.
    :param url: (optional) URL to fetch as string.
    :param insecure: (optional) Allow insecure HTTPS connections if bool `True`.
    :param size: (optional) Size of import as int.
    """
    def __init__(self, **kwargs):
        self.id = kwargs.get('id', None)
        self.user_id = kwargs.get('user_id', None)
        self.created = kwargs.get('created', None)
        self.updated = kwargs.get('updated', None)
        self.archive = kwargs.get('archive', None)
        self.path = kwargs.get('path', None)
        self.url = kwargs.get('url', None)
        self.insecure = kwargs.get('insecure', None)
        self.size = kwargs.get('size', None)

class ImportSchema(Schema):
    id = fields.Int(as_string=True)
    user_id = fields.Int(as_string=True)

    created = DateTime()