import click
import influxframework


def execute():
	if "education" in influxframework.get_installed_apps():
		return

	influxframework.delete_doc("Workspace", "Education", ignore_missing=True, force=True)

	pages = influxframework.get_all("Page", {"module": "education"}, pluck="name")
	for page in pages:
		influxframework.delete_doc("Page", page, ignore_missing=True, force=True)

	reports = influxframework.get_all("Report", {"module": "education", "is_standard": "Yes"}, pluck="name")
	for report in reports:
		influxframework.delete_doc("Report", report, ignore_missing=True, force=True)

	print_formats = influxframework.get_all(
		"Print Format", {"module": "education", "standard": "Yes"}, pluck="name"
	)
	for print_format in print_formats:
		influxframework.delete_doc("Print Format", print_format, ignore_missing=True, force=True)

	influxframework.reload_doc("website", "doctype", "website_settings")
	forms = influxframework.get_all("Web Form", {"module": "education", "is_standard": 1}, pluck="name")
	for form in forms:
		influxframework.delete_doc("Web Form", form, ignore_missing=True, force=True)

	dashboards = influxframework.get_all("Dashboard", {"module": "education", "is_standard": 1}, pluck="name")
	for dashboard in dashboards:
		influxframework.delete_doc("Dashboard", dashboard, ignore_missing=True, force=True)

	dashboards = influxframework.get_all(
		"Dashboard Chart", {"module": "education", "is_standard": 1}, pluck="name"
	)
	for dashboard in dashboards:
		influxframework.delete_doc("Dashboard Chart", dashboard, ignore_missing=True, force=True)

	influxframework.reload_doc("desk", "doctype", "number_card")
	cards = influxframework.get_all("Number Card", {"module": "education", "is_standard": 1}, pluck="name")
	for card in cards:
		influxframework.delete_doc("Number Card", card, ignore_missing=True, force=True)

	doctypes = influxframework.get_all("DocType", {"module": "education", "custom": 0}, pluck="name")
	for doctype in doctypes:
		influxframework.delete_doc("DocType", doctype, ignore_missing=True)

	influxframework.delete_doc("Module Def", "Education", ignore_missing=True, force=True)

	click.secho(
		"Education Module is moved to a separate app"
		"Please install the app to continue using the module: https://github.com/influxframework/education",
		fg="yellow",
	)
