from app import db

class Base(db.Model):

    __abstract__  = True

    id            = db.Column(db.Integer, primary_key=True)
    date_created  = db.Column(db.DateTime,  default=db.func.current_timestamp())
    date_modified = db.Column(db.DateTime,  default=db.func.current_timestamp(),
                                           onupdate=db.func.current_timestamp())
class User(Base):

    __tablename__ = 'User'    

    nickname = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash= db.Column(db.String(128))
    

    @staticmethod
    def make_unique_nickname(nickname):
        if User.query.filter_by(nickname=nickname).first() is None:
            return nickname
        version = 2
        while True:
            new_nickname = nickname + str(version)
            if User.query.filter_by(nickname=new_nickname).first() is None:
                break
            version += 1
        return new_nickname

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

	
    def load_user(user_id):
	return User.query.get(int(user_id))

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        try:
            return unicode(self.id)  # python 2
        except NameError:
            return str(self.id)  # python 3


    def __init__(self, nickname, email, password_hash):

        self.nickname     = nickname
        self.email    = email
        self.password_hash=password_hash
        
	

    def __repr__(self):
        return '<User %r>' % (self.nickname)

	


class Museums(Base):

    __tablename__ = 'Museums'     

    nickname = db.Column(db.String(64), index=True, unique=True)
    body = db.Column(db.String(140))


    def verificar_body_relleno(body):
	if body is None:
		return False

	if body is not None:
		return True

    def __init__(self,nickname,body):

	self.nickname = nickname
        self.body = body
        

    def __repr__(self):
        return '<Museums %r>' % (self.body)
