# 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 collections
from functools import partial
from marshmallow import Schema, fields, post_load
from .cdr_datetime import DateTime
from .cdr_dictfield import DictField

class AddrCountSchema(Schema):
    addr = fields.Str()
    count = fields.Int(as_string=True)

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

class AllStats(object):
    """Model for CDRouter All Alerts Stats.

    :param severities: (optional) Dict of ints to :class:`alerts.SeverityCount <alerts.SeverityCount>`
    :param categories: (optional) :class:`alerts.CategoryCount <alerts.CategoryCount>` list
    :param rule_sets: (optional) :class:`alerts.RuleSetCount <alerts.RuleSetCount>` list
    :param signatures: (optional) :class:`alerts.SignatureCount <alerts.SignatureCount>` list
    :param tests: (optional) :class:`alerts.TestCount <alerts.TestCount>` list
    :param frequent_sources: (optional) :class:`alerts.AddrCount <alerts.AddrCount>` list
    :param frequent_destinations: (optional) :class:`alerts.AddrCount <alerts.AddrCount>` list
    """
    def __init__(self, **kwargs):
        self.severities = kwargs.get('severities', None)
        self.categories = kwargs.get('categories', None)
        self.rule_sets = kwargs.get('rule_sets', None)
        self.signatures = kwargs.get('signatures', None)
        self.tests = kwargs.get('tests', None)
        self.frequent_sources = kwargs.get('frequent_sources', None)
        self.frequent_destinations = kwargs.get('frequent_destinations', None)

class AllStatsSchema(Schema):

# 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/alerts.py
import collections
from functools import partial
from marshmallow import Schema, fields, post_load
from .cdr_datetime import DateTime
from .cdr_dictfield import DictField


class AddrCountSchema(Schema):
    addr = fields.Str()
    count = fields.Int(as_string=True)

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

class AllStats(object):
    """Model for CDRouter All Alerts Stats.

    :param severities: (optional) Dict of ints to :class:`alerts.SeverityCount <alerts.SeverityCount>`
    :param categories: (optional) :class:`alerts.CategoryCount <alerts.CategoryCount>` list
    :param rule_sets: (optional) :class:`alerts.RuleSetCount <alerts.RuleSetCount>` list
    :param signatures: (optional) :class:`alerts.SignatureCount <alerts.SignatureCount>` list
    :param tests: (optional) :class:`alerts.TestCount <alerts.TestCount>` list
    :param frequent_sources: (optional) :class:`alerts.AddrCount <alerts.AddrCount>` list
    :param frequent_destinations: (optional) :class:`alerts.AddrCount <alerts.AddrCount>` list
    """
    def __init__(self, **kwargs):
        self.severities = kwargs.get('severities', None)
        self.categories = kwargs.get('categories', None)
        self.rule_sets = kwargs.get('rule_sets', None)
        self.signatures = kwargs.get('signatures', None)
        self.tests = kwargs.get('tests', None)
        self.frequent_sources = kwargs.get('frequent_sources', None)
        self.frequent_destinations = kwargs.get('frequent_destinations', None)

class AllStatsSchema(Schema):

    severities = DictField(fields.Int(), SeverityCountSchema())