# Path: template_maker/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=False, ondelete=None, pk_name='id', **kwargs):
# 
# Path: template_maker/users/models.py
# class User(UserMixin, SurrogatePK, Model):
# 
#     __tablename__ = 'users'
#     email = Column(db.String(80), unique=True, nullable=False)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     first_name = Column(db.String(30), nullable=True)
#     last_name = Column(db.String(30), nullable=True)
#     active = Column(db.Boolean(), default=False)
#     is_admin = Column(db.Boolean(), default=False)
# 
#     def __init__(self, email, **kwargs):
#         db.Model.__init__(self, email=email, **kwargs)
# 
#     @property
#     def full_name(self):
#         return "{0} {1}".format(self.first_name, self.last_name)
# 
#     def __repr__(self):
#         return '<User({email!r})>'.format(email=self.email)


from template_maker.database import (
    Column,
    Model,
    db,
    ReferenceCol,
)
from template_maker.users.models import User
from sqlalchemy.dialects.postgres import ARRAY
IMPLEMENTED_SECTIONS = [cls.choice_type for cls in vars()['TemplateSection'].__subclasses__()]

class PlaceholderTypes(Model):
    '''
    The types associated with different placeholders. We use a FK
    constraint to make sure it's one of the approved tyes

    Fields:
    - type: The name of the type in question
    '''
    __tablename__ = 'placeholder_types'
    id = Column(db.Integer, primary_key=True)
    type = Column(db.Text)

class TemplatePlaceholders(Model):
    '''
    The placeholders associated with each section

    Fields:
    - name: The actual name of the placeholder
    - template_id: Foreign Key back to the TemplateBase model
    - section_id: Foreign Key back to the TemplateSection model
    '''

    __tablename__ = 'template_placeholders'
    id = Column(db.Integer, primary_key=True)
    full_name = Column(db.Text)
    display_name = Column(db.Text)
    type = Column(db.Integer, db.ForeignKey('placeholder_types.id'))
    template_id = ReferenceCol('template_base')

# Path: template_maker/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=False, ondelete=None, pk_name='id', **kwargs):
# 
# Path: template_maker/users/models.py
# class User(UserMixin, SurrogatePK, Model):
# 
#     __tablename__ = 'users'
#     email = Column(db.String(80), unique=True, nullable=False)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     first_name = Column(db.String(30), nullable=True)
#     last_name = Column(db.String(30), nullable=True)
#     active = Column(db.Boolean(), default=False)
#     is_admin = Column(db.Boolean(), default=False)
# 
#     def __init__(self, email, **kwargs):
#         db.Model.__init__(self, email=email, **kwargs)
# 
#     @property
#     def full_name(self):
#         return "{0} {1}".format(self.first_name, self.last_name)
# 
#     def __repr__(self):
#         return '<User({email!r})>'.format(email=self.email)


# Path: template_maker/builder/models.py
from template_maker.database import (
    Column,
    Model,
    db,
    ReferenceCol,
)
from template_maker.users.models import User
from sqlalchemy.dialects.postgres import ARRAY

IMPLEMENTED_SECTIONS = [cls.choice_type for cls in vars()['TemplateSection'].__subclasses__()]

class PlaceholderTypes(Model):
    '''
    The types associated with different placeholders. We use a FK
    constraint to make sure it's one of the approved tyes

    Fields:
    - type: The name of the type in question
    '''
    __tablename__ = 'placeholder_types'
    id = Column(db.Integer, primary_key=True)
    type = Column(db.Text)

class TemplatePlaceholders(Model):
    '''
    The placeholders associated with each section

    Fields:
    - name: The actual name of the placeholder
    - template_id: Foreign Key back to the TemplateBase model
    - section_id: Foreign Key back to the TemplateSection model
    '''

    __tablename__ = 'template_placeholders'
    id = Column(db.Integer, primary_key=True)
    full_name = Column(db.Text)
    display_name = Column(db.Text)
    type = Column(db.Integer, db.ForeignKey('placeholder_types.id'))
    template_id = ReferenceCol('template_base')

    section_id = ReferenceCol('template_section')