from app.extensions import db

class ProjectAccess(db.Model):
    __tablename__ = 'project_access'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    project_id = db.Column(db.Integer, db.ForeignKey('projekte.id'), nullable=False)
    zugriff = db.Column(db.String(20), default='lesen')

    user = db.relationship('User', backref='project_access_list')
    project = db.relationship('Project', backref='user_access_list')

    __table_args__ = (db.UniqueConstraint('user_id', 'project_id'),)

    def __repr__(self):
        return f'<ProjectAccess u={self.user_id} p={self.project_id} {self.zugriff}>'
