import sys

from command_parser import parse, Commands
from oracle import Oracle
from prompts import default_prompt, Prompts, action_prompt, description_prompt



oracle = Oracle()
table = Oracle.table

print("Welcome to the oracle.\n\n")

while True:
    print("\nCommand>", end = " ")
    cmd = str(input())
    parsed = parse(cmd)
    print("\n")

    if parsed == None:
        print("Type help or h to see the help text.")
    elif parsed.cmd == Commands.Exit:
        print("Thanks for this time.\n")
        sys.exit()
    elif parsed.cmd == Commands.Help and parsed.arg == True:
        print("""
Welcome to my little Mythic helper. To understand whats happening you need to read the rules.

Type commands with optional argument to get results. Alternate ways of writing commands and
arguments are displayed in brackets.

---
oracle [o]:
  Returns a yes or now answer. And possible an random event indication.
    
  argument:
    The argument should be how likely the question generates an yes answer among:
            
      certain [c, 4]
      nearlycertain [nc, 3]
      verylikely [vl, 2]
      likely [l, 1]
      even [e, 0, 50/50]
      unlikely [u, -1]
      veryunlikely [vu, -2]
      nearlyimpossible [ni, -3]
      impossible [i, -4]
            
      If you leave the argument out it will default to even.

---
chaos [c]:
  Sets the chaos factor.
  
  argument:
    a number between 1 and 9 (inclusive) - If the value is left out it is set to 5.
      
---
prompt [p]:
  Returns a prompt that you can use to interpret a result or a situation.
  
  argument:
    The argument specifies how the prompt should be generated.
    
      default [d] - Generates a verb plus noun prompt. This is the default if an argument is left out.
      action [a] - Generates an action prompt.
      description [dd, ds] - Generates a description prompt.

---            
help [h]:
  Return this help text.

---    
exit [e]:
  Exits the program.   
        """)
    elif parsed.cmd == Commands.Help and parsed.arg is None:
        print("Type help or h to see the help text.")
    elif parsed.cmd == Commands.AskOracle:
        answer = oracle.ask_oracle(parsed.arg)
        for line in answer:
            print(line)
    elif parsed.cmd == Commands.Prompt:
        if parsed.arg == Prompts.Default:
            print(default_prompt())
        elif parsed.arg == Prompts.Action:
            print(action_prompt())
        elif parsed.arg == Prompts.Description:
            print(description_prompt())