from datetime import datetime

import Models
from app import db


class ModerationFlagsModel(Models.Base):
    __tablename__ = 'moderation_flags'

    user_id = db.Column(db.ForeignKey('user.id'), primary_key=True)
    user = db.relationship(
        "UserModel",
        back_populates="moderation_flags"
    )
    is_developer = db.Column(db.Boolean, nullable=False, default=False)
    is_moderator = db.Column(db.Boolean, nullable=False, default=False)
    can_post = db.Column(db.Boolean, nullable=False, default=True)
    can_delete = db.Column(db.Boolean, nullable=False, default=False)
    can_ban = db.Column(db.Boolean, nullable=False, default=False)
    can_match = db.Column(db.Boolean, nullable=False, default=True)
    message_anyone = db.Column(db.Boolean, nullable=False, default=False)
    muted_till = db.Column(db.DateTime, nullable=False, default=datetime(2000, 1, 1))
    banned_till = db.Column(db.DateTime, nullable=False, default=datetime(2000, 1, 1))

    def is_muted(self):
        return self.muted_till > datetime.utcnow()

    def is_banned(self):
        return self.banned_till > datetime.utcnow()
