from sqlalchemy.orm import Session
from app.model.user_room_model import UserRoom


class UserRoomDAO:
    def __init__(self, db_session: Session):
        self.db_session = db_session

    def get_all(self):
        return self.db_session.query(UserRoom).all()

    def get_by_id(self, record_id: int):
        return self.db_session.query(UserRoom).get(record_id)

    def get_by_user_account(self, user_account: str):
        return self.db_session.query(UserRoom).filter_by(user_account=user_account).all()

    def get_by_room_id(self, room_id: str):
        return self.db_session.query(UserRoom).filter_by(room_id=room_id).all()

    def get_unique(self, user_account: str, room_id: str):
        return self.db_session.query(UserRoom).filter_by(user_account=user_account, room_id=room_id).first()

    def create(self, record: UserRoom):
        self.db_session.add(record)
        self.db_session.commit()
        return record

    def update(self, record: UserRoom):
        self.db_session.commit()
        return record

    def delete(self, record: UserRoom):
        self.db_session.delete(record)
        self.db_session.commit()


