import uuid

from sqlalchemy.dialects.postgresql import UUID

import Models
from app import db


class ProjectTypeModel(Models.Base):
    __tablename__ = 'project_types'

    id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    en = db.Column(db.String, nullable=False)
    de = db.Column(db.String, nullable=False)

    def get_name(self, lang):
        if lang and 'de' in lang:
            return self.de
        else:
            return self.en

    @staticmethod
    def from_string(string):
        return ProjectTypeModel.query.filter((ProjectTypeModel.en == string) | (ProjectTypeModel.de == string)).first()

    @staticmethod
    def get_default():
        return ProjectTypeModel.query.get('c49d9f25-f244-4a1e-af35-67c235c62bfa')
