from app import db


class UserRoom(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_account = db.Column(db.String(120), nullable=False, index=True)
    room_id = db.Column(db.String(120), nullable=False, index=True)

    __table_args__ = (
        db.UniqueConstraint('user_account', 'room_id', name='uq_user_account_room_id'),
    )

    def to_dict(self):
        return {
            'id': self.id,
            'user_account': self.user_account,
            'room_id': self.room_id,
        }

    def __repr__(self):
        return f'<UserRoom {self.id}: {self.user_account}-{self.room_id}>'


