# Path: vulyk/blueprints/gamification/core/foundations.py
# class Fund:
#     """
#     Outer representation of different foundations we should keep:
#     donatable or not they are.
#     """
#     __slots__ = [
#         'id',
#         'name',
#         'description',
#         'site',
#         'email',
#         'logo',
#         'donatable'
#     ]
# 
#     def __init__(self,
#                  fund_id: str,
#                  name: str,
#                  description: str,
#                  site: str,
#                  email: str,
#                  logo: IOBase,
#                  donatable: bool) -> None:
#         # let's put it manually to use as an alias
#         """
#         :type fund_id: str
#         :type name: str
#         :type description: str
#         :type site: str
#         :type email: str
#         :type logo: IOBase
#         :type donatable: bool
#         """
#         self.id = fund_id
#         self.name = name
#         self.description = description
#         self.site = site
#         self.email = email
#         # this one should be an image file or *FSProxy, not sure yet
#         self.logo = logo
#         self.donatable = donatable
# 
#     def to_dict(self) -> Dict[str, str]:
#         """
#         Could be used as a source for JSON or any other representation format
# 
#         :return: Dict-ized object view
#         :rtype: dict
#         """
#         return {
#             'id': self.id,
#             'name': self.name,
#             'description': self.description,
#             'site': self.site,
#             'email': self.email,
#             'donatable': self.donatable
#         }
# 
#     def __eq__(self, o: object) -> bool:
#         if isinstance(o, Fund):
#             return o.id == self.id and o.name == self.name
#         else:
#             return False
# 
#     def __ne__(self, o: object) -> bool:
#         return not self == o
# 
#     def __str__(self) -> str:
#         return 'Fund({id}, {name}, {descr}, {site}, {email}, {donat})'.format(
#             id=self.id,
#             name=self.name,
#             descr=self.description[:20],
#             site=self.site,
#             email=self.email,
#             donat=self.donatable)
# 
#     def __repr__(self) -> str:
#         return str(self)


from enum import Enum
from typing import Iterator, Optional
from flask_mongoengine import Document
from mongoengine import (
    StringField, EmailField, ImageField, BooleanField, Q
)
from ..core.foundations import Fund
class FundFilterBy(Enum):
    """
    The intent of this enum is to represent filtering policies.
    """
    NO_FILTER = 0
    DONATABLE = 1
    NON_DONATABLE = 2


class FundModel(Document):
    """
    Database-specific foundation representation
    """
    id = StringField(required=True, max_length=50, primary_key=True)
    name = StringField(required=True)
    description = StringField(required=True)
    site = StringField(required=False)
    email = EmailField(required=False, allow_utf8_user=True)
    logo = ImageField(unique=True, thumbnail_size=(141, 106, True))
    donatable = BooleanField(required=True)

    meta = {
        'collection': 'gamification.funds',
        'allow_inheritance': True,
        'indexes': [
            'name',
            'donatable'
        ]
    }


# Path: vulyk/blueprints/gamification/core/foundations.py
# class Fund:
#     """
#     Outer representation of different foundations we should keep:
#     donatable or not they are.
#     """
#     __slots__ = [
#         'id',
#         'name',
#         'description',
#         'site',
#         'email',
#         'logo',
#         'donatable'
#     ]
# 
#     def __init__(self,
#                  fund_id: str,
#                  name: str,
#                  description: str,
#                  site: str,
#                  email: str,
#                  logo: IOBase,
#                  donatable: bool) -> None:
#         # let's put it manually to use as an alias
#         """
#         :type fund_id: str
#         :type name: str
#         :type description: str
#         :type site: str
#         :type email: str
#         :type logo: IOBase
#         :type donatable: bool
#         """
#         self.id = fund_id
#         self.name = name
#         self.description = description
#         self.site = site
#         self.email = email
#         # this one should be an image file or *FSProxy, not sure yet
#         self.logo = logo
#         self.donatable = donatable
# 
#     def to_dict(self) -> Dict[str, str]:
#         """
#         Could be used as a source for JSON or any other representation format
# 
#         :return: Dict-ized object view
#         :rtype: dict
#         """
#         return {
#             'id': self.id,
#             'name': self.name,
#             'description': self.description,
#             'site': self.site,
#             'email': self.email,
#             'donatable': self.donatable
#         }
# 
#     def __eq__(self, o: object) -> bool:
#         if isinstance(o, Fund):
#             return o.id == self.id and o.name == self.name
#         else:
#             return False
# 
#     def __ne__(self, o: object) -> bool:
#         return not self == o
# 
#     def __str__(self) -> str:
#         return 'Fund({id}, {name}, {descr}, {site}, {email}, {donat})'.format(
#             id=self.id,
#             name=self.name,
#             descr=self.description[:20],
#             site=self.site,
#             email=self.email,
#             donat=self.donatable)
# 
#     def __repr__(self) -> str:
#         return str(self)


# Path: vulyk/blueprints/gamification/models/foundations.py
from enum import Enum
from typing import Iterator, Optional
from flask_mongoengine import Document
from mongoengine import (
    StringField, EmailField, ImageField, BooleanField, Q
)
from ..core.foundations import Fund

class FundFilterBy(Enum):
    """
    The intent of this enum is to represent filtering policies.
    """
    NO_FILTER = 0
    DONATABLE = 1
    NON_DONATABLE = 2


class FundModel(Document):
    """
    Database-specific foundation representation
    """
    id = StringField(required=True, max_length=50, primary_key=True)
    name = StringField(required=True)
    description = StringField(required=True)
    site = StringField(required=False)
    email = EmailField(required=False, allow_utf8_user=True)
    logo = ImageField(unique=True, thumbnail_size=(141, 106, True))
    donatable = BooleanField(required=True)

    meta = {
        'collection': 'gamification.funds',
        'allow_inheritance': True,
        'indexes': [
            'name',
            'donatable'
        ]
    }


    def to_fund(self) -> Fund: