#!/usr/bin/env python

import github.account.rate_limit as rate_limit
from helpers.choices import prompt
from helpers.clear import clear

def main():
	clear()

	# Get the users current GitHub rate limiting status
	rate_limit_data = rate_limit.get()
	# if rate_limit_data["error"] exists print that and return.
	if "error" in rate_limit_data:
		print(rate_limit_data["error"])
		return

	print(f'You have used {rate_limit_data["used"]} out of {rate_limit_data["limit"]} requests', end='\n')
	print(f'You have {rate_limit_data["remaining"]} requests remaining', end='\n')
	print(f'Your rate limit will reset at {rate_limit_data["reset"]}', end='\n')

	# present the user with options to choose from the issues, prs, and releases folder.
	report = prompt('Which report do you want to generate?', ['Pull Requests', 'Issues Opened', 'Releases', 'L10 Report', 'Exit'], False)

	# based on the user's choice, import the appropriate module and call the main function
	if report == '1':
		pr_report = prompt('Which report do you want to generate?', ['Opened', 'Closed'])

		if pr_report == '1':
			import github.prs.created as prs_created
			prs_created.count()

		elif pr_report == '2':
			import github.prs.closed as prs_closed
			prs_closed.count()

		else:
			print('Invalid choice')

	elif report == '2':
		from github.issues.opened import count
		count()

	elif report == '3':
		release_report = prompt( 'Which report do you want to generate?', ['Release Notes', 'Release Stats'])
		if release_report == '1':
			import github.releases.notes as releases_notes
			releases_notes.generate()

		elif release_report == '2':
			print('Nothing to see here yet')

		else:
			print('Invalid choice')

	elif report == '4':
		clear()

		input_date = input('Optionally enter the date for the L10 report (YYYY-MM-DD): ')
		if input_date.strip() == "":
			input_date = None

		import github.issues.opened as issues_opened
		import github.prs.created as prs_created
		import github.prs.closed as prs_closed
		issues_opened.summary(input_date)
		prs_created.summary(input_date)
		prs_closed.summary(input_date)
	else:
		# exit the program
		exit()

	again = prompt('Do you want to generate another report?', ['Yes', 'No'], False)
	if again == '1' or again == 'y' or again == 'Y' or again == 'yes' or again == 'Yes' or again == 'YES':
		main()
	else:
		exit()

if __name__ == '__main__':
	main()
