import uuid

from sqlalchemy import Table
from sqlalchemy.dialects.postgresql import UUID

import Models
from app import db

matchable_users_table = Table('declare', Models.Base.metadata,
                              db.Column('user_id', db.ForeignKey('user.id')),
                              db.Column('group_matching_id', db.ForeignKey('group_matching_declarations.id')))


class GroupMatchingDeclarationModel(Models.Base):
    __tablename__ = 'group_matching_declarations'

    id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    matchable_users = db.relationship(
        "UserModel",
        secondary=matchable_users_table
    )
    declared_project_id = db.Column(db.ForeignKey('project.id'), nullable=True)
    declared_project = db.relationship(
        "ProjectModel",
        foreign_keys=declared_project_id
    )
