import sqlalchemy as sa
from sqlalchemy.orm import relationship

from common import databases as db

class Organization(db.AuthBase):
    __tablename__ = 'organization'

    id = sa.Column(sa.Integer, primary_key=True)
    description = sa.Column(sa.String(100), nullable=False)
    database = sa.Column(sa.String(100), nullable=False)
    deleted = sa.Column(sa.Boolean, nullable=False)
    inactive = sa.Column(sa.Boolean, nullable=False)
    created = sa.Column(sa.DateTime, nullable=False)
    updated = sa.Column(sa.DateTime)
    memberships = relationship("Membership", backref="organization")


    @classmethod
    def active_orgs(cls):
        orgs = db.auth_session().query(cls).filter(cls.inactive==False).\
            filter(cls.deleted==False).all()
        return orgs

