#!python

import os
from theatre_cli.config import load_config, save_config
from theatre_cli.movie import set_movie_dir, list_movies
from theatre_cli.player import choose_player_and_play

def main():
    config_data = load_config()

    if not config_data or config_data[0].get("first_time", "").lower() == "true":
        print('Performing first-time setup...')
        req_dir = int(input("Do you have a movies directory or would you like to make one?\n0: Use an existing one\n1: Make a new one\nEnter choice: "))
        if req_dir:
            movie_dir = set_movie_dir()
        elif req_dir == 0:
            movie_dir = input("Enter the directory path (from home dir): ")
        else:
            print("Enter a valid choice!")
            exit(0)

        config_data = [{
            "first_time": "false",
            "username": os.environ.get('USERNAME'),
            "home_dir": os.path.expanduser('~'),
            "movie_dir": movie_dir
        }]
        save_config(config_data)

    movie_dir = config_data[0]['movie_dir']
    choose_player_and_play(movie_dir)

if __name__ == "__main__":
    main()
