from pathlib import Path


def image_filepath(shot, output_filepath, train=True):
    """ Get the image file path from the shot (meta)data. """
    train_subdir = 'train' if train else 'test'
    goal_subdir = 'goal' if shot['shot']['outcome']['name'] == 'Goal' else 'no-goal'

    shot_dir = Path(output_filepath)/train_subdir/goal_subdir
    shot_dir.mkdir(parents=True, exist_ok=True)

    filename = f'{shot["id"]}.png'
    return shot_dir/filename