# Path: nflpool/data/dbsession.py
# class DbSessionFactory:
#     factory = None
# 
#     # Start a database session at app startup
#     @staticmethod
#     def global_init(db_file):
#         if DbSessionFactory.factory:
#             return
# 
#         if not db_file or not db_file.strip():
#             raise Exception("You must specify a data file.")
# 
#         conn_str = "sqlite:///" + db_file
#         print("Connecting to db with conn string: {}".format(conn_str))
# 
#         engine = sqlalchemy.create_engine(conn_str, echo=False)
# 
#         SqlAlchemyBase.metadata.create_all(engine)
#         DbSessionFactory.factory = sqlalchemy.orm.sessionmaker(bind=engine)
# 
#     @staticmethod
#     def create_session():
#         return DbSessionFactory.factory()
# 
# Path: nflpool/data/account.py
# class Account(SqlAlchemyBase):
#     __tablename__ = "Account"
# 
#     id = Column(
#         String, primary_key=True, default=lambda: str(uuid.uuid4()).replace("-", "")
#     )
# 
#     email = Column(String, index=True, unique=True, nullable=False)
#     first_name = Column(String, nullable=False)
#     last_name = Column(String, nullable=False)
#     password_hash = Column(String)
#     created = Column(DateTime, default=datetime.datetime.now)
#     email_confirmed = Column(Boolean, nullable=False, default=False)
#     is_super_user = Column(Boolean, nullable=False, default=False)
#     twitter = Column(String, nullable=True)
#     paid = Column(Integer, default=0)
# 
# Path: nflpool/data/player_picks.py
# class PlayerPicks(SqlAlchemyBase):
#     __tablename__ = "PlayerPicks"
#     pick_id = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True
#     )
#     user_id = sqlalchemy.Column(sqlalchemy.String, sqlalchemy.ForeignKey("Account.id"))
#     season = sqlalchemy.Column(sqlalchemy.Integer, index=True)
#     date_submitted = sqlalchemy.Column(sqlalchemy.DATETIME)
#     conf_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ConferenceInfo.conf_id")
#     )
#     division_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("DivisionInfo.division_id")
#     )
#     rank = sqlalchemy.Column(sqlalchemy.Integer)
#     team_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("TeamInfo.team_id")
#     )
#     multiplier = sqlalchemy.Column(sqlalchemy.Integer, default=1)
#     player_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ActiveNFLPlayers.player_id")
#     )
#     pick_type = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("PickTypes.pick_type_id")
#     )
# 
# Path: nflpool/data/teaminfo.py
# class TeamInfo(SqlAlchemyBase):
#     __tablename__ = "TeamInfo"
#     team_id = sqlalchemy.Column(sqlalchemy.Integer, index=True, primary_key=True)
#     name = sqlalchemy.Column(sqlalchemy.String)
#     city = sqlalchemy.Column(sqlalchemy.String)
#     team_abbr = sqlalchemy.Column(sqlalchemy.String)
#     conference_id = sqlalchemy.Column(sqlalchemy.Integer)
#     division_id = sqlalchemy.Column(sqlalchemy.Integer)
# 
# Path: nflpool/data/conferenceinfo.py
# class ConferenceInfo(SqlAlchemyBase):
#     __tablename__ = "ConferenceInfo"
#     conf_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     conference = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/divisioninfo.py
# class DivisionInfo(SqlAlchemyBase):
#     __tablename__ = "DivisionInfo"
#     division_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     division = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/activeplayers.py
# class ActiveNFLPlayers(SqlAlchemyBase):
#     __tablename__ = "ActiveNFLPlayers"
#     primary_key = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True, index=True
#     )
#     season = sqlalchemy.Column(sqlalchemy.Integer)
#     team_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("TeamInfo.team_id")
#     )
#     firstname = sqlalchemy.Column(sqlalchemy.String)
#     lastname = sqlalchemy.Column(sqlalchemy.String)
#     position = sqlalchemy.Column(sqlalchemy.String, index=True)
#     player_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("PlayerPicks.player_id"), index=True
#     )


from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.account import Account
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.teaminfo import TeamInfo
from nflpool.data.conferenceinfo import ConferenceInfo
from nflpool.data.divisioninfo import DivisionInfo
from nflpool.data.activeplayers import ActiveNFLPlayers
from sqlalchemy import and_
    @classmethod
    def seasons_played(cls, user_id):
        session = DbSessionFactory.create_session()

        seasons_played = (
            session.query(PlayerPicks.season)
            .distinct(PlayerPicks.season)
            .filter(Account.id == user_id)
        )

        return seasons_played

    @staticmethod
    def display_picks(user_id, season):

        session = DbSessionFactory.create_session()

        picks_query = (
            session.query(
                PlayerPicks.pick_type,
                ConferenceInfo.conference,
                DivisionInfo.division,
                TeamInfo.name,
                PlayerPicks.rank,
                ActiveNFLPlayers.firstname,
                ActiveNFLPlayers.lastname,
                PlayerPicks.multiplier,
            )
            .outerjoin(ConferenceInfo)
            .outerjoin(DivisionInfo)

# Path: nflpool/data/dbsession.py
# class DbSessionFactory:
#     factory = None
# 
#     # Start a database session at app startup
#     @staticmethod
#     def global_init(db_file):
#         if DbSessionFactory.factory:
#             return
# 
#         if not db_file or not db_file.strip():
#             raise Exception("You must specify a data file.")
# 
#         conn_str = "sqlite:///" + db_file
#         print("Connecting to db with conn string: {}".format(conn_str))
# 
#         engine = sqlalchemy.create_engine(conn_str, echo=False)
# 
#         SqlAlchemyBase.metadata.create_all(engine)
#         DbSessionFactory.factory = sqlalchemy.orm.sessionmaker(bind=engine)
# 
#     @staticmethod
#     def create_session():
#         return DbSessionFactory.factory()
# 
# Path: nflpool/data/account.py
# class Account(SqlAlchemyBase):
#     __tablename__ = "Account"
# 
#     id = Column(
#         String, primary_key=True, default=lambda: str(uuid.uuid4()).replace("-", "")
#     )
# 
#     email = Column(String, index=True, unique=True, nullable=False)
#     first_name = Column(String, nullable=False)
#     last_name = Column(String, nullable=False)
#     password_hash = Column(String)
#     created = Column(DateTime, default=datetime.datetime.now)
#     email_confirmed = Column(Boolean, nullable=False, default=False)
#     is_super_user = Column(Boolean, nullable=False, default=False)
#     twitter = Column(String, nullable=True)
#     paid = Column(Integer, default=0)
# 
# Path: nflpool/data/player_picks.py
# class PlayerPicks(SqlAlchemyBase):
#     __tablename__ = "PlayerPicks"
#     pick_id = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True
#     )
#     user_id = sqlalchemy.Column(sqlalchemy.String, sqlalchemy.ForeignKey("Account.id"))
#     season = sqlalchemy.Column(sqlalchemy.Integer, index=True)
#     date_submitted = sqlalchemy.Column(sqlalchemy.DATETIME)
#     conf_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ConferenceInfo.conf_id")
#     )
#     division_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("DivisionInfo.division_id")
#     )
#     rank = sqlalchemy.Column(sqlalchemy.Integer)
#     team_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("TeamInfo.team_id")
#     )
#     multiplier = sqlalchemy.Column(sqlalchemy.Integer, default=1)
#     player_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ActiveNFLPlayers.player_id")
#     )
#     pick_type = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("PickTypes.pick_type_id")
#     )
# 
# Path: nflpool/data/teaminfo.py
# class TeamInfo(SqlAlchemyBase):
#     __tablename__ = "TeamInfo"
#     team_id = sqlalchemy.Column(sqlalchemy.Integer, index=True, primary_key=True)
#     name = sqlalchemy.Column(sqlalchemy.String)
#     city = sqlalchemy.Column(sqlalchemy.String)
#     team_abbr = sqlalchemy.Column(sqlalchemy.String)
#     conference_id = sqlalchemy.Column(sqlalchemy.Integer)
#     division_id = sqlalchemy.Column(sqlalchemy.Integer)
# 
# Path: nflpool/data/conferenceinfo.py
# class ConferenceInfo(SqlAlchemyBase):
#     __tablename__ = "ConferenceInfo"
#     conf_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     conference = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/divisioninfo.py
# class DivisionInfo(SqlAlchemyBase):
#     __tablename__ = "DivisionInfo"
#     division_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     division = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/activeplayers.py
# class ActiveNFLPlayers(SqlAlchemyBase):
#     __tablename__ = "ActiveNFLPlayers"
#     primary_key = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True, index=True
#     )
#     season = sqlalchemy.Column(sqlalchemy.Integer)
#     team_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("TeamInfo.team_id")
#     )
#     firstname = sqlalchemy.Column(sqlalchemy.String)
#     lastname = sqlalchemy.Column(sqlalchemy.String)
#     position = sqlalchemy.Column(sqlalchemy.String, index=True)
#     player_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("PlayerPicks.player_id"), index=True
#     )


# Path: nflpool/services/view_picks_service.py
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.account import Account
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.teaminfo import TeamInfo
from nflpool.data.conferenceinfo import ConferenceInfo
from nflpool.data.divisioninfo import DivisionInfo
from nflpool.data.activeplayers import ActiveNFLPlayers
from sqlalchemy import and_

    @classmethod
    def seasons_played(cls, user_id):
        session = DbSessionFactory.create_session()

        seasons_played = (
            session.query(PlayerPicks.season)
            .distinct(PlayerPicks.season)
            .filter(Account.id == user_id)
        )

        return seasons_played

    @staticmethod
    def display_picks(user_id, season):

        session = DbSessionFactory.create_session()

        picks_query = (
            session.query(
                PlayerPicks.pick_type,
                ConferenceInfo.conference,
                DivisionInfo.division,
                TeamInfo.name,
                PlayerPicks.rank,
                ActiveNFLPlayers.firstname,
                ActiveNFLPlayers.lastname,
                PlayerPicks.multiplier,
            )
            .outerjoin(ConferenceInfo)
            .outerjoin(DivisionInfo)

            .outerjoin(TeamInfo)