# coding=utf-8
from __future__ import absolute_import, unicode_literals, division
from moarcofy.models.photo import Photo
from moarcofy.models.user import User
from moarcofy import auto_modified

from mongoengine import *  # noqa
from datetime import datetime


@auto_modified
class Album(Document):
    meta = {"indexes": [
        "owner",
        [("owner", 1), ("name", "text"), ("description", "text")],
        "photos"
    ]}

    # general meta
    name = StringField(required=True, max_length=128)
    description = StringField(default="", max_length=4096)
    owner = ReferenceField(User, reverse_delete_rule=CASCADE)

    # photo information
    photos = ListField(ReferenceField(Photo, reverse_delete_rule=PULL))

    # dates
    created = DateTimeField(default=datetime.now)
    modified = DateTimeField(default=datetime.now)
