import click
import xhiveframework


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

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

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

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

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

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

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

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

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

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

	xhiveframework.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/xhiveframework/education",
		fg="yellow",
	)
