import datetime
from pathlib import Path
from Generators.AudioClips_Generator import generate_audio_clips
from Generators.BingoGames_Generator import generate_bingo_games
from Generators.Prediction_Generator import generate_predictions


# Measure time
start_time = datetime.datetime.now()

# Define the paths for song cutting
full_songs_dir = Path('Files/FullSongs').absolute()
clipped_music_dir = Path('Files/ClippedSongs').absolute()

# Define the path for song cutting XLS
xlsx_path = Path('Assets/Index.xlsx').absolute()

# Define the path for backspin sample
backspin_sample_path = Path('Assets/Backspin_2.mp3').absolute()
# Define the path for backspin sample
countdown_sample_path = Path('Assets/Countdown.mp3').absolute()

# Define the path for the bingo card template
template_path = Path('Assets/Template.jpeg').absolute()

# Define the path for generating games
games_master_dir = Path('Files/GeneratedGames').absolute()

# Parameters for music clip generation
clip_duration_secs = 30

# Define parameters for game generation
games_to_generate = 1
songs_per_game = 50
cards_per_game = 25

# Parameters for card
master_code = '200418_SG'  # Unique identifier for a particular game
rows_per_card = 4
cols_per_card = 4

# Define operations
overwrite_music_clips = False
generate_music_clips = True
generate_games = True
predict_results = True


#################################################################
# DO NOT EDIT THE CODE BELOW UNLESS YOU KNOW WHAT YOU'RE DOING! #
#################################################################

# Execute operations
if generate_music_clips:

    params = {
        'input_dir': full_songs_dir,
        'output_dir': clipped_music_dir,
        'xlsx_path': xlsx_path,
        'backspin_path': backspin_sample_path,
        'clip_duration_secs': clip_duration_secs,
        'overwrite': overwrite_music_clips
    }
    generate_audio_clips(params)
    print(f'All songs clipped by {datetime.datetime.now() - start_time}\n')

if generate_games:

    params = {
        'master_code': master_code,
        'games_master_dir': games_master_dir,
        'games_to_generate': games_to_generate,
        'clipped_music_dir': clipped_music_dir,
        'countdown_sample_path': countdown_sample_path,
        'songs_per_game': songs_per_game,
        'cards_per_game': cards_per_game,
        'rows_per_card': rows_per_card,
        'cols_per_card': cols_per_card,
        'template_path': template_path,
        'predict_results': predict_results
    }

    print('Generating games')
    generate_bingo_games(params)
    print(f'{games_to_generate} games generated by {datetime.datetime.now() - start_time}\n')

if predict_results:
    print('Generating predictions')
    generate_predictions(games_master_dir, master_code)
    print(f'{games_to_generate} predictions generated by {datetime.datetime.now() - start_time}')
