#!/usr/bin/env python3

import colorama
from sys import argv, exit

from src.survey import Survey
from src.recorder import Recorder
from src.interviewer import Interviewer

def take_survey():
    r = Recorder()
    s = Survey()
    i = Interviewer(s)

    while len(s):
        i.ask_next_question()
   
    r.add_survey(s)

    print()
    print(f'total score: {colorama.Fore.BLUE}{s.total()}{colorama.Style.RESET_ALL}')

def list_surveys():
    r = Recorder()
    print()
    for date, score in r.list_surveys().items():
        print(f'{date}     {score}')
    print()

def print_usage():
    print()
    print("phq9 usage:")
    print("  $ phq9 take # takes the survey")
    print("  $ phq9 list # read past survey results")
    print()

# remove the name of the script from argv (e.g. ['path/to/phq9', 'take'] -> ['take'])
del argv[0]

# if user didn't pass a param, print usage and exit
if len(argv) < 1:
    print_usage()
    exit()

# route valid requests
if argv[0] == "take":
    take_survey()
elif argv[0] == "list":
    list_surveys()
else:
    print_usage()

