import asyncio
import sys

from creation_helpers import pd_players_df
from db_calls import db_post
from defenders.calcs_defense import get_bbref_fielding_df
from pitchers.creation import create_position


async def main(args):
    all_cardsets = [(2008, 12), (2013, 6), (2022, 3), (2023, 9)]
    # all_cardsets = [(2008, 12)]

    for year, cardset_id in all_cardsets:
        print(f'Running {year} now...')
        all_players = await pd_players_df(cardset_id)
        df_p = get_bbref_fielding_df('p', year)

        pitcher_df = all_players.merge(df_p, left_on='bbref_id', right_on='key_bbref')

        await create_position(
            season_pct=1.00,
            pitching_stats=pitcher_df,
            post_pitchers=True,
            df_p=df_p
        )

        print(f'Resetting images...')
        pitcher_ids = pitcher_df['player_id']
        for x in pitcher_ids:
            await db_post(f'players/{x}/image-reset')


if __name__ == '__main__':
    asyncio.run(main(sys.argv[1:]))
