"""
Models for pages.

:copyright: Copyright 2013-2016, Dorian Pula <dorian.pula@amber-penguin-software.ca>
:license: AGPL v3+
"""

import sqlalchemy

from rookeries import database


class Page(database.ModelBase):
    __tablename__ = 'page'

    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    # TODO: Move out into the definition of app / container blocks.
    slug = sqlalchemy.Column(sqlalchemy.String(64), unique=True)
    title = sqlalchemy.Column(sqlalchemy.String(256))
    # TODO: Break out into content blocks.
    content = sqlalchemy.Column(sqlalchemy.String)

    # TODO: Add in content type, created, updated dates and author (based on a user).

    def __init__(self, slug, title, content):
        self.slug = slug
        self.title = title
        self.content = content

    def __repr__(self) -> str:
        return '<JournalEntry {!r}>'.format(self.slug)

    def to_json(self) -> dict:
        return {
            'slug': self.slug,
            'title': self.title,
            'content': self.content,
        }
