# 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/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/data/seasoninfo.py
# class SeasonInfo(SqlAlchemyBase):
#     __tablename__ = "SeasonInfo"
#     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
#     current_season = sqlalchemy.Column(sqlalchemy.Integer)
#     season_start_date = sqlalchemy.Column(sqlalchemy.String)
#     home_team = sqlalchemy.Column(sqlalchemy.String)
#     away_team = sqlalchemy.Column(sqlalchemy.String)


import requests
import nflpool.data.secret as secret
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.activeplayers import ActiveNFLPlayers
from requests.auth import HTTPBasicAuth
from nflpool.data.seasoninfo import SeasonInfo


"""After updating the season to a new year, get all active NFL players and add to the database to be
used by NFLPool players to choose from when submitting their picks.  The Try / Except is needed for 
players who may not have a position assigned yet."""


class ActivePlayersService:
    @classmethod
    def add_active_nflplayers(
        cls,
        season: int,
        team_id: int,
        firstname: str,
        lastname: str,
        position: str,
        player_id: int,
    ):

        session = DbSessionFactory.create_session()


# 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/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/data/seasoninfo.py
# class SeasonInfo(SqlAlchemyBase):
#     __tablename__ = "SeasonInfo"
#     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
#     current_season = sqlalchemy.Column(sqlalchemy.Integer)
#     season_start_date = sqlalchemy.Column(sqlalchemy.String)
#     home_team = sqlalchemy.Column(sqlalchemy.String)
#     away_team = sqlalchemy.Column(sqlalchemy.String)


# Path: nflpool/services/activeplayers_service.py
import requests
import nflpool.data.secret as secret
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.activeplayers import ActiveNFLPlayers
from requests.auth import HTTPBasicAuth
from nflpool.data.seasoninfo import SeasonInfo



"""After updating the season to a new year, get all active NFL players and add to the database to be
used by NFLPool players to choose from when submitting their picks.  The Try / Except is needed for 
players who may not have a position assigned yet."""


class ActivePlayersService:
    @classmethod
    def add_active_nflplayers(
        cls,
        season: int,
        team_id: int,
        firstname: str,
        lastname: str,
        position: str,
        player_id: int,
    ):

        session = DbSessionFactory.create_session()


        season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()