class TeamService:
    def __init__(self):
        self.con = DBConfig().connection()

    def get_all(self):
        return self.con.query(TeamModel).all()

    def save(self, name, city):
        team = TeamModel()
        team.name = name
        team.city = city
        self.con.add(team)
        self.con.commit()
        return team

    def get_by_filter_all(self, name, city):
        return self.con.query(TeamModel).filter(
            TeamModel.name == name, TeamModel.city == city).first()
class BookService:
    def __init__(self):
        self.con = DBConfig().connection()

    def all(self):
        return self.con.query(BookModel).all()

    def save(self, **kwargs):
        try:
            pm = BookModel()
            pm.name = kwargs.get("name")
            pm.author = kwargs.get("author")
            pm.reader_id = kwargs.get("reader_id")
            self.con.add(pm)
            self.con.commit()
            return True
        except Exception as e:
            self.con.rollback()
            raise e
class PlayerService:
    def __init__(self):
        self.con = DBConfig().connection()

    def all(self):
        return self.con.query(PlayerModel).all()

    def save(self, **kwargs):
        try:
            pm = PlayerModel()
            pm.name = kwargs.get("name")
            pm.position = kwargs.get("position")
            pm.team_id = kwargs.get("team_id")
            self.con.add(pm)
            self.con.commit()
            return True
        except Exception as e:
            self.con.rollback()
            raise e
class ReaderService:

    def __init__(self):
        self.con = DBConfig().connection()

    def all(self):
        return self.con.query(ReaderModel).all()

    def save(self, **kwargs):
        try:
            rm = ReaderModel()
            rm.name = kwargs.get("name")
            self.con.add(rm)
            self.con.commit()
            return rm
        except Exception as e:
            self.con.rollback()
            raise e

    def get_by_filter(self, name):
        return self.con.query(ReaderModel).filter(ReaderModel.name == name).first()