# 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/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/services/time_service.py
# class TimeService:
#     @staticmethod
#     def get_time():
#         """Create a service to get the time - there were too many instances of getting the current time in
#         the codebase making testing difficult."""
#         # Change now_time for testing
#         # Use this one for production:
#         now_time = pendulum.now(tz=pendulum.timezone("America/New_York"))
#         # Use this one for testing:
#         # now_time = pendulum.datetime(2018, 9, 18, 6, 21, tz='America/New_York')
# 
#         return now_time
# 
#     @staticmethod
#     def get_week():
#         session = DbSessionFactory.create_session()
#         season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
# 
#         season_start = pendulum.parse(season_row.season_start_date)
# 
#         diff = TimeService.get_time() - season_start
#         week = int((diff.days / 7) + 1)
# 
#         return week


import pendulum
from nflpool.data.seasoninfo import SeasonInfo
from nflpool.data.dbsession import DbSessionFactory
from nflpool.services.time_service import TimeService


# Set the timezone we will be working with
timezone = pendulum.timezone("America/New_York")

# Don't change this - change the now_time in TimeService
now_time = TimeService.get_time()


def season_opener():

    session = DbSessionFactory.create_session()

    season_start_query = session.query(SeasonInfo.season_start_date).first()
    # print("Season Start Query:", season_start_query)

    # season_start_query is returned as a tuple and need to get the first part of the tuple:
    season_opener_date = str(season_start_query[0])

    # Use the string above in a Pendulum instance and get the time deltas needed
    season_start_date = pendulum.parse(season_opener_date, tz=timezone)

    session.close()

    return season_start_date


class GameDayService:
    @staticmethod
    def admin_check():

# 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/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/services/time_service.py
# class TimeService:
#     @staticmethod
#     def get_time():
#         """Create a service to get the time - there were too many instances of getting the current time in
#         the codebase making testing difficult."""
#         # Change now_time for testing
#         # Use this one for production:
#         now_time = pendulum.now(tz=pendulum.timezone("America/New_York"))
#         # Use this one for testing:
#         # now_time = pendulum.datetime(2018, 9, 18, 6, 21, tz='America/New_York')
# 
#         return now_time
# 
#     @staticmethod
#     def get_week():
#         session = DbSessionFactory.create_session()
#         season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
# 
#         season_start = pendulum.parse(season_row.season_start_date)
# 
#         diff = TimeService.get_time() - season_start
#         week = int((diff.days / 7) + 1)
# 
#         return week


# Path: nflpool/services/gameday_service.py
import pendulum
from nflpool.data.seasoninfo import SeasonInfo
from nflpool.data.dbsession import DbSessionFactory
from nflpool.services.time_service import TimeService



# Set the timezone we will be working with
timezone = pendulum.timezone("America/New_York")

# Don't change this - change the now_time in TimeService
now_time = TimeService.get_time()


def season_opener():

    session = DbSessionFactory.create_session()

    season_start_query = session.query(SeasonInfo.season_start_date).first()
    # print("Season Start Query:", season_start_query)

    # season_start_query is returned as a tuple and need to get the first part of the tuple:
    season_opener_date = str(season_start_query[0])

    # Use the string above in a Pendulum instance and get the time deltas needed
    season_start_date = pendulum.parse(season_opener_date, tz=timezone)

    session.close()

    return season_start_date


class GameDayService:
    @staticmethod
    def admin_check():

        session = DbSessionFactory.create_session()