import uuid

from sqlalchemy.dialects.postgresql import UUID

import Models
from app import db


class QuestionsModel(Models.Base):
    __tablename__ = 'questions'

    id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    official = db.Column(db.Boolean, nullable=False, default=True)
    question_en = db.Column(db.String, nullable=False)
    question_de = db.Column(db.String, nullable=False)
    placeholder_en = db.Column(db.String, nullable=False)
    placeholder_de = db.Column(db.String, nullable=False)

    def get_question(self, lang):
        if lang and 'de' in lang:
            return self.question_de
        else:
            return self.question_en

    def get_placeholder(self, lang):
        if lang and 'de' in lang:
            return self.placeholder_de
        else:
            return self.placeholder_en

    @staticmethod
    def from_string(question):
        return QuestionsModel.query.filter(
            (QuestionsModel.question_en == question) | (QuestionsModel.question_de == question)).first()
