import examples
import generator
from run import run
from reader import read

print("This tool will handle the following (in order):")
print("1. Pair up mentors and students in preference order if they have each other in their ranked list.")
print("At this point no more mentors/students with mutual rankings exist.")
print("2. Pair up mentors and students with students' preference order. Forcefully pair a mentor to the students' preference.")
print("At this point the students' preferences are all taken.")
print("3. Pair up mentors and students with mentors' preference order. Forcefully pair up a student to the mentors' preference.")
print("At this point everyone's preferences can be as met as possible. Unfortunately whoever is left could not find who they want or be wanted.")
print("4. Randomly pair up the remaining groups.")
print()
print("NOTE: This tool handles a mentor handling multiple students but it does NOT handle a situation where a student has multiple mentors.")
while True:
  print()
  print("### Semi Stable Marriage - yuwilbur ###")
  print("- See examples.py for what an importable data looks like")
  print("- Generate an example to create an importable data")
  print()
  print("Options:")
  print("1: Copy-paste google spreadsheet data")
  print("2: Run an pre-existing example")
  print("3: Generate and run a random example")
  print("4: Copy-paste raw importable data")
  print()
  option = input("Choose an option (Input a number): ")
  print()
  if option == "4":
    students_data = input("Paste serialized students data: ")
    print()
    mentors_data = input("Paste serialized mentors data: ")
    print()
    run(students_data, mentors_data)
  elif option == "2":
    print("Select example:")
    print("1: Simple")
    print("2: Complex")
    option = input("Select an example (Input a number): ")
    print()
    if option == "1":
      print("Running simple example...")
      print()
      run(examples.simple_students, examples.simple_mentors) 
    elif option == "2":
      print("Running complex example...")
      print()
      run(examples.complex_students, examples.complex_mentors) 
  elif option == "3":
      print("Generating an example requires further inputs.")
      students_data = generator.GeneratorData()
      students_data.total = int(input("How many total student groups? (Input a number): "))
      students_data.rankings_count = int(input("How many mentor groups can a student group rank? (Input a number): "))
      mentors_data = generator.GeneratorData()
      mentors_data.total = int(input("How many total mentor groups? (Input a number): "))
      mentors_data.rankings_count = int(input("How many student groups can a mentor group rank? (Input a number): "))
      mentors_data.matches_count = int(input("How many student groups can a mentor group take on? (Input a number): "))
      data = generator.generate(students_data, mentors_data)
      option = input("Do you want to see generated data? [y/n]: ")
      print()
      if option == "y":
        print("Students Data:")
        print()
        print(data["students"])
        print()
        print("Mentors Data:")
        print()
        print(data["mentors"])
        print()
      option = input("Do you want to run generated data? [y/n]: ")
      print()
      if option == "y":
        run(data["students"], data["mentors"])
  elif option == "1":
      print("To use this option, you'll need to format your spreadsheet correctly:")
      print("<team #>, <matches allowed>, <rank #1>, <rank #2>, <rank #3>, ...")
      print()
      print("Example:")
      print("Student Team #2 with 1 > 4 > 3")
      print("Mentor Team #1 with rank 2 > 4 > 6 and can handle 3 student groups")
      print("Mentor Team #4 with rank 1 > 3 > 5 and can handle 1 student group")
      print()
      print("Student's spreadsheet copy-paste (TITLE IS NOT REQUIRED) :")
      print("2 1 1 4 3")
      print()
      print("Mentor's spreadsheet copy-paste (TITLE IS NOT REQUIRED) :")
      print("1 3 2 4 6")
      print("4 1 1 3 5")
      print()
      print("NOTICE: Student's <matches allowed> must be 1")
      print()
      students = read("Students")
      print()
      mentors = read("Mentors")
      print()
      option = input("Run with this data? [y/n]: ")
      print()
      if option == "y":
        run(students, mentors)
