# NOTE: os and sys are library usually for troubleshooting purpose
import os,sys
import numpy as np

# NOTE: prepare prize table for lookup,
prize_table = [
  ['1st', 21531600],
  ['2nd', 885990],
  ['3rd', 157500],
  ['4th', 9600],
  ['5th', 640],
  ['6th', 320],
  ['7th', 40],
]

def prize_matching(all_drawn_number, user_entry_nums):
  """
  A function that calculates the prize based on matching numbers with user entries.
  Parameters:
      all_drawn_number (tuple): Tuple containing a list of drawn numbers and an extra number.
      user_entry_nums (list): List of user's chosen numbers.
  Returns:
      list: A list representing the prize won.
  """
  # NOTE:
  prize = ['',0]
  [drawn_numbers, extra_number] = all_drawn_number

  # NOTE: find number of match in drawn numbers with user entry numbers
  matched_number = 0
  for user_num in user_entry_nums:
    for drawn_number in drawn_numbers:
      if (drawn_number == user_num):
        matched_number = matched_number + 1
        break

  # NOTE: find if any extra number match user entry number
  matched_extra_number = 0
  for user_num in user_entry_nums:
    if (user_num == extra_number):
      matched_extra_number = matched_extra_number + 1
      break

  if (matched_number == 6):
    # first_prize = True
    prize = prize_table[0]
  elif (matched_number == 5 and matched_extra_number == 1):
    # second_prize = True
    prize = prize_table[1]
  elif (matched_number == 5):
    # third_prize = True
    prize = prize_table[2]
  elif (matched_number == 4 and matched_extra_number == 1):
    # forth_prize = True
    prize = prize_table[3]
  elif (matched_number == 4):
    # fifth_prize = True
    prize = prize_table[4]
  elif (matched_number == 3 and matched_extra_number == 1):
    # sixth_prize = True
    prize = prize_table[5]
  elif (matched_number == 3):
    # seventh_prize = True
    prize = prize_table[6]
  else:
    # no prize matched
    pass
  return prize

def print_output(prize_result, user_entry_nums):
  # deliver prize message
  print("Numbers of your entry: ", user_entry_nums)
  print('')
  print('Result :')
  if (prize_result[1] > 0):
    print("Output prize = " + str(prize_result[0]) + " = $" + str(prize_result[1]))
  else:
    print("No prize given")
  pass


keep_asking = True
while keep_asking:
  # part a
  user_entry_numbers = input("Please entry 6 numbers of your choice:")
  user_entry_numbers = eval(user_entry_numbers)

  # NOTE: check if number of user entered is not equal to 6
  len_equal_to_six = False
  if (len(user_entry_numbers) != 6):
    print('user entered numbers should be exactly 6')
    print('Please input the correct number.')
    print()
  else:
    len_equal_to_six = True

  # NOTE: check if each number within range
  numbers_are_in_range = True
  for user_num in user_entry_numbers:
    if (user_num < 1 or user_num > 49):
      print('user entered number should be within 1 to 49')
      print('Please input the correct number.')
      print()
      numbers_are_in_range = False
      break

  if (len_equal_to_six == True and numbers_are_in_range == True):
    keep_asking = False

# part b
# drawn 7 numbers
# init seed randomizer
np.random.seed(21800000)

# init empty slot for number
temp_numbers = np.arange(0, 7, 1, dtype=int)

# [1,2,3,4,5,6,7]
temp_numbers = np.random.choice(range(1,49), 7)

# the first 6 number are considered drawn number
# [1,2,3,4,5,6]
drawn_nums = temp_numbers[0:6].tolist()

# the last one considered extra number
# 7
extra_num = temp_numbers[6]

# re-format number to duple
# ([1,2,3,4,5,6],7)
all_drawn_nums = (drawn_nums, extra_num)

# part a
print("all drawn numbers: ", all_drawn_nums)
print("drawn numbers: " , drawn_nums)
print("extra number: " , extra_num)

# part a
result = prize_matching(all_drawn_nums, user_entry_numbers)
print_output(result, user_entry_numbers)
