from . import __version__ as app_version

app_name = "xhiveframework"
app_title = "XhiveFramework Framework"
app_publisher = "XhiveFramework Technologies"
app_description = "Full stack web framework with Python, Javascript, MariaDB, Redis, Node"
source_link = "https://github.com/xhiveframework/xhiveframework"
app_license = "MIT"
app_logo_url = "/assets/xhiveframework/images/xhive-framework-logo.svg"

develop_version = "14.x.x-develop"

app_email = "developers@xhiveframework.co"

docs_app = "xhiveframework_docs"

translator_url = "https://translate.xhiveerp.co"

before_install = "xhiveframework.utils.install.before_install"
after_install = "xhiveframework.utils.install.after_install"

page_js = {"setup-wizard": "public/js/xhiveframework/setup_wizard.js"}

# website
app_include_js = [
	"libs.bundle.js",
	"desk.bundle.js",
	"list.bundle.js",
	"form.bundle.js",
	"controls.bundle.js",
	"report.bundle.js",
]
app_include_css = [
	"desk.bundle.css",
	"report.bundle.css",
]

doctype_js = {
	"Web Page": "public/js/xhiveframework/utils/web_template.js",
	"Website Settings": "public/js/xhiveframework/utils/web_template.js",
}

web_include_js = ["website_script.js"]

web_include_css = []

email_css = ["email.bundle.css"]

website_route_rules = [
	{"from_route": "/blog/<category>", "to_route": "Blog Post"},
	{"from_route": "/kb/<category>", "to_route": "Help Article"},
	{"from_route": "/newsletters", "to_route": "Newsletter"},
	{"from_route": "/profile", "to_route": "me"},
	{"from_route": "/app/<path:app_path>", "to_route": "app"},
]

website_redirects = [
	{"source": r"/desk(.*)", "target": r"/app\1"},
]

base_template = "templates/base.html"

write_file_keys = ["file_url", "file_name"]

notification_config = "xhiveframework.core.notifications.get_notification_config"

before_tests = "xhiveframework.utils.install.before_tests"

email_append_to = ["Event", "ToDo", "Communication"]

calendars = ["Event"]

leaderboards = "xhiveframework.desk.leaderboard.get_leaderboards"

# login

on_session_creation = [
	"xhiveframework.core.doctype.activity_log.feed.login_feed",
	"xhiveframework.core.doctype.user.user.notify_admin_access_to_system_manager",
]

on_logout = (
	"xhiveframework.core.doctype.session_default_settings.session_default_settings.clear_session_defaults"
)

# permissions

permission_query_conditions = {
	"Event": "xhiveframework.desk.doctype.event.event.get_permission_query_conditions",
	"ToDo": "xhiveframework.desk.doctype.todo.todo.get_permission_query_conditions",
	"User": "xhiveframework.core.doctype.user.user.get_permission_query_conditions",
	"Dashboard Settings": "xhiveframework.desk.doctype.dashboard_settings.dashboard_settings.get_permission_query_conditions",
	"Notification Log": "xhiveframework.desk.doctype.notification_log.notification_log.get_permission_query_conditions",
	"Dashboard": "xhiveframework.desk.doctype.dashboard.dashboard.get_permission_query_conditions",
	"Dashboard Chart": "xhiveframework.desk.doctype.dashboard_chart.dashboard_chart.get_permission_query_conditions",
	"Number Card": "xhiveframework.desk.doctype.number_card.number_card.get_permission_query_conditions",
	"Notification Settings": "xhiveframework.desk.doctype.notification_settings.notification_settings.get_permission_query_conditions",
	"Note": "xhiveframework.desk.doctype.note.note.get_permission_query_conditions",
	"Kanban Board": "xhiveframework.desk.doctype.kanban_board.kanban_board.get_permission_query_conditions",
	"Contact": "xhiveframework.contacts.address_and_contact.get_permission_query_conditions_for_contact",
	"Address": "xhiveframework.contacts.address_and_contact.get_permission_query_conditions_for_address",
	"Communication": "xhiveframework.core.doctype.communication.communication.get_permission_query_conditions_for_communication",
	"Workflow Action": "xhiveframework.workflow.doctype.workflow_action.workflow_action.get_permission_query_conditions",
	"Prepared Report": "xhiveframework.core.doctype.prepared_report.prepared_report.get_permission_query_condition",
}

has_permission = {
	"Event": "xhiveframework.desk.doctype.event.event.has_permission",
	"ToDo": "xhiveframework.desk.doctype.todo.todo.has_permission",
	"User": "xhiveframework.core.doctype.user.user.has_permission",
	"Note": "xhiveframework.desk.doctype.note.note.has_permission",
	"Dashboard Chart": "xhiveframework.desk.doctype.dashboard_chart.dashboard_chart.has_permission",
	"Number Card": "xhiveframework.desk.doctype.number_card.number_card.has_permission",
	"Kanban Board": "xhiveframework.desk.doctype.kanban_board.kanban_board.has_permission",
	"Contact": "xhiveframework.contacts.address_and_contact.has_permission",
	"Address": "xhiveframework.contacts.address_and_contact.has_permission",
	"Communication": "xhiveframework.core.doctype.communication.communication.has_permission",
	"Workflow Action": "xhiveframework.workflow.doctype.workflow_action.workflow_action.has_permission",
	"File": "xhiveframework.core.doctype.file.file.has_permission",
	"Prepared Report": "xhiveframework.core.doctype.prepared_report.prepared_report.has_permission",
}

has_website_permission = {
	"Address": "xhiveframework.contacts.doctype.address.address.has_website_permission"
}

jinja = {
	"methods": "xhiveframework.utils.jinja_globals",
	"filters": [
		"xhiveframework.utils.data.global_date_format",
		"xhiveframework.utils.markdown",
		"xhiveframework.website.utils.get_shade",
		"xhiveframework.website.utils.abs_url",
	],
}

standard_queries = {"User": "xhiveframework.core.doctype.user.user.user_query"}

doc_events = {
	"*": {
		"after_insert": [
			"xhiveframework.event_streaming.doctype.event_update_log.event_update_log.notify_consumers"
		],
		"on_update": [
			"xhiveframework.desk.notifications.clear_doctype_notifications",
			"xhiveframework.core.doctype.activity_log.feed.update_feed",
			"xhiveframework.workflow.doctype.workflow_action.workflow_action.process_workflow_actions",
			"xhiveframework.automation.doctype.assignment_rule.assignment_rule.apply",
			"xhiveframework.core.doctype.file.utils.attach_files_to_document",
			"xhiveframework.event_streaming.doctype.event_update_log.event_update_log.notify_consumers",
			"xhiveframework.automation.doctype.assignment_rule.assignment_rule.update_due_date",
			"xhiveframework.core.doctype.user_type.user_type.apply_permissions_for_non_standard_user_type",
		],
		"after_rename": "xhiveframework.desk.notifications.clear_doctype_notifications",
		"on_cancel": [
			"xhiveframework.desk.notifications.clear_doctype_notifications",
			"xhiveframework.workflow.doctype.workflow_action.workflow_action.process_workflow_actions",
			"xhiveframework.event_streaming.doctype.event_update_log.event_update_log.notify_consumers",
		],
		"on_trash": [
			"xhiveframework.desk.notifications.clear_doctype_notifications",
			"xhiveframework.workflow.doctype.workflow_action.workflow_action.process_workflow_actions",
			"xhiveframework.event_streaming.doctype.event_update_log.event_update_log.notify_consumers",
		],
		"on_update_after_submit": [
			"xhiveframework.workflow.doctype.workflow_action.workflow_action.process_workflow_actions"
		],
		"on_change": [
			"xhiveframework.social.doctype.energy_point_rule.energy_point_rule.process_energy_points",
			"xhiveframework.automation.doctype.milestone_tracker.milestone_tracker.evaluate_milestone",
		],
	},
	"Event": {
		"after_insert": "xhiveframework.integrations.doctype.google_calendar.google_calendar.insert_event_in_google_calendar",
		"on_update": "xhiveframework.integrations.doctype.google_calendar.google_calendar.update_event_in_google_calendar",
		"on_trash": "xhiveframework.integrations.doctype.google_calendar.google_calendar.delete_event_from_google_calendar",
	},
	"Contact": {
		"after_insert": "xhiveframework.integrations.doctype.google_contacts.google_contacts.insert_contacts_to_google_contacts",
		"on_update": "xhiveframework.integrations.doctype.google_contacts.google_contacts.update_contacts_to_google_contacts",
	},
	"DocType": {
		"on_update": "xhiveframework.cache_manager.build_domain_restriced_doctype_cache",
	},
	"Page": {
		"on_update": "xhiveframework.cache_manager.build_domain_restriced_page_cache",
	},
}

scheduler_events = {
	"cron": {
		"0/15 * * * *": [
			"xhiveframework.oauth.delete_oauth2_data",
			"xhiveframework.website.doctype.web_page.web_page.check_publish_status",
			"xhiveframework.twofactor.delete_all_barcodes_for_users",
		]
	},
	"all": [
		"xhiveframework.email.queue.flush",
		"xhiveframework.email.doctype.email_account.email_account.pull",
		"xhiveframework.email.doctype.email_account.email_account.notify_unreplied",
		"xhiveframework.utils.global_search.sync_global_search",
		"xhiveframework.monitor.flush",
	],
	"hourly": [
		"xhiveframework.model.utils.link_count.update_link_count",
		"xhiveframework.model.utils.user_settings.sync_user_settings",
		"xhiveframework.utils.error.collect_error_snapshots",
		"xhiveframework.desk.page.backups.backups.delete_downloadable_backups",
		"xhiveframework.deferred_insert.save_to_db",
		"xhiveframework.desk.form.document_follow.send_hourly_updates",
		"xhiveframework.integrations.doctype.google_calendar.google_calendar.sync",
		"xhiveframework.email.doctype.newsletter.newsletter.send_scheduled_email",
		"xhiveframework.website.doctype.personal_data_deletion_request.personal_data_deletion_request.process_data_deletion_request",
	],
	"daily": [
		"xhiveframework.email.queue.set_expiry_for_email_queue",
		"xhiveframework.desk.notifications.clear_notifications",
		"xhiveframework.desk.doctype.event.event.send_event_digest",
		"xhiveframework.sessions.clear_expired_sessions",
		"xhiveframework.email.doctype.notification.notification.trigger_daily_alerts",
		"xhiveframework.website.doctype.personal_data_deletion_request.personal_data_deletion_request.remove_unverified_record",
		"xhiveframework.desk.form.document_follow.send_daily_updates",
		"xhiveframework.social.doctype.energy_point_settings.energy_point_settings.allocate_review_points",
		"xhiveframework.integrations.doctype.google_contacts.google_contacts.sync",
		"xhiveframework.automation.doctype.auto_repeat.auto_repeat.make_auto_repeat_entry",
		"xhiveframework.automation.doctype.auto_repeat.auto_repeat.set_auto_repeat_as_completed",
		"xhiveframework.email.doctype.unhandled_email.unhandled_email.remove_old_unhandled_emails",
		"xhiveframework.core.doctype.prepared_report.prepared_report.delete_expired_prepared_reports",
		"xhiveframework.core.doctype.log_settings.log_settings.run_log_clean_up",
	],
	"daily_long": [
		"xhiveframework.integrations.doctype.dropbox_settings.dropbox_settings.take_backups_daily",
		"xhiveframework.utils.change_log.check_for_update",
		"xhiveframework.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_daily",
		"xhiveframework.email.doctype.auto_email_report.auto_email_report.send_daily",
		"xhiveframework.integrations.doctype.google_drive.google_drive.daily_backup",
	],
	"weekly_long": [
		"xhiveframework.integrations.doctype.dropbox_settings.dropbox_settings.take_backups_weekly",
		"xhiveframework.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_weekly",
		"xhiveframework.desk.form.document_follow.send_weekly_updates",
		"xhiveframework.social.doctype.energy_point_log.energy_point_log.send_weekly_summary",
		"xhiveframework.integrations.doctype.google_drive.google_drive.weekly_backup",
	],
	"monthly": [
		"xhiveframework.email.doctype.auto_email_report.auto_email_report.send_monthly",
		"xhiveframework.social.doctype.energy_point_log.energy_point_log.send_monthly_summary",
	],
	"monthly_long": [
		"xhiveframework.integrations.doctype.s3_backup_settings.s3_backup_settings.take_backups_monthly"
	],
}

get_translated_dict = {
	("doctype", "System Settings"): "xhiveframework.geo.country_info.get_translated_dict",
	("page", "setup-wizard"): "xhiveframework.geo.country_info.get_translated_dict",
}

sounds = [
	{"name": "email", "src": "/assets/xhiveframework/sounds/email.mp3", "volume": 0.1},
	{"name": "submit", "src": "/assets/xhiveframework/sounds/submit.mp3", "volume": 0.1},
	{"name": "cancel", "src": "/assets/xhiveframework/sounds/cancel.mp3", "volume": 0.1},
	{"name": "delete", "src": "/assets/xhiveframework/sounds/delete.mp3", "volume": 0.05},
	{"name": "click", "src": "/assets/xhiveframework/sounds/click.mp3", "volume": 0.05},
	{"name": "error", "src": "/assets/xhiveframework/sounds/error.mp3", "volume": 0.1},
	{"name": "alert", "src": "/assets/xhiveframework/sounds/alert.mp3", "volume": 0.2},
	# {"name": "chime", "src": "/assets/xhiveframework/sounds/chime.mp3"},
]

setup_wizard_exception = [
	"xhiveframework.desk.page.setup_wizard.setup_wizard.email_setup_wizard_exception",
	"xhiveframework.desk.page.setup_wizard.setup_wizard.log_setup_wizard_exception",
]

before_migrate = []
after_migrate = ["xhiveframework.website.doctype.website_theme.website_theme.after_migrate"]

otp_methods = ["OTP App", "Email", "SMS"]

user_data_fields = [
	{"doctype": "Access Log", "strict": True},
	{"doctype": "Activity Log", "strict": True},
	{"doctype": "Comment", "strict": True},
	{
		"doctype": "Contact",
		"filter_by": "email_id",
		"redact_fields": ["first_name", "last_name", "phone", "mobile_no"],
		"rename": True,
	},
	{"doctype": "Contact Email", "filter_by": "email_id"},
	{
		"doctype": "Address",
		"filter_by": "email_id",
		"redact_fields": [
			"address_title",
			"address_line1",
			"address_line2",
			"city",
			"county",
			"state",
			"pincode",
			"phone",
			"fax",
		],
	},
	{
		"doctype": "Communication",
		"filter_by": "sender",
		"redact_fields": ["sender_full_name", "phone_no", "content"],
	},
	{"doctype": "Communication", "filter_by": "recipients"},
	{"doctype": "Email Group Member", "filter_by": "email"},
	{"doctype": "Email Unsubscribe", "filter_by": "email", "partial": True},
	{"doctype": "Email Queue", "filter_by": "sender"},
	{"doctype": "Email Queue Recipient", "filter_by": "recipient"},
	{
		"doctype": "File",
		"filter_by": "attached_to_name",
		"redact_fields": ["file_name", "file_url"],
	},
	{
		"doctype": "User",
		"filter_by": "name",
		"redact_fields": [
			"email",
			"username",
			"first_name",
			"middle_name",
			"last_name",
			"full_name",
			"birth_date",
			"user_image",
			"phone",
			"mobile_no",
			"location",
			"banner_image",
			"interest",
			"bio",
			"email_signature",
		],
	},
	{"doctype": "Version", "strict": True},
]

global_search_doctypes = {
	"Default": [
		{"doctype": "Contact"},
		{"doctype": "Address"},
		{"doctype": "ToDo"},
		{"doctype": "Note"},
		{"doctype": "Event"},
		{"doctype": "Blog Post"},
		{"doctype": "Dashboard"},
		{"doctype": "Country"},
		{"doctype": "Currency"},
		{"doctype": "Newsletter"},
		{"doctype": "Letter Head"},
		{"doctype": "Workflow"},
		{"doctype": "Web Page"},
		{"doctype": "Web Form"},
	]
}

override_whitelisted_methods = {
	# Legacy File APIs
	"xhiveframework.core.doctype.file.file.download_file": "download_file",
	"xhiveframework.core.doctype.file.file.unzip_file": "xhiveframework.core.api.file.unzip_file",
	"xhiveframework.core.doctype.file.file.get_attached_images": "xhiveframework.core.api.file.get_attached_images",
	"xhiveframework.core.doctype.file.file.get_files_in_folder": "xhiveframework.core.api.file.get_files_in_folder",
	"xhiveframework.core.doctype.file.file.get_files_by_search_text": "xhiveframework.core.api.file.get_files_by_search_text",
	"xhiveframework.core.doctype.file.file.get_max_file_size": "xhiveframework.core.api.file.get_max_file_size",
	"xhiveframework.core.doctype.file.file.create_new_folder": "xhiveframework.core.api.file.create_new_folder",
	"xhiveframework.core.doctype.file.file.move_file": "xhiveframework.core.api.file.move_file",
	"xhiveframework.core.doctype.file.file.zip_files": "xhiveframework.core.api.file.zip_files",
	# Legacy (& Consistency) OAuth2 APIs
	"xhiveframework.www.login.login_via_google": "xhiveframework.integrations.oauth2_logins.login_via_google",
	"xhiveframework.www.login.login_via_github": "xhiveframework.integrations.oauth2_logins.login_via_github",
	"xhiveframework.www.login.login_via_facebook": "xhiveframework.integrations.oauth2_logins.login_via_facebook",
	"xhiveframework.www.login.login_via_xhiveframework": "xhiveframework.integrations.oauth2_logins.login_via_xhiveframework",
	"xhiveframework.www.login.login_via_office365": "xhiveframework.integrations.oauth2_logins.login_via_office365",
	"xhiveframework.www.login.login_via_salesforce": "xhiveframework.integrations.oauth2_logins.login_via_salesforce",
	"xhiveframework.www.login.login_via_fairlogin": "xhiveframework.integrations.oauth2_logins.login_via_fairlogin",
}

ignore_links_on_delete = [
	"Communication",
	"ToDo",
	"DocShare",
	"Email Unsubscribe",
	"Activity Log",
	"File",
	"Version",
	"Document Follow",
	"Comment",
	"View Log",
	"Tag Link",
	"Notification Log",
	"Email Queue",
	"Document Share Key",
	"Integration Request",
	"Unhandled Email",
	"Webhook Request Log",
]

# Request Hooks
before_request = [
	"xhiveframework.recorder.record",
	"xhiveframework.monitor.start",
	"xhiveframework.rate_limiter.apply",
]
after_request = ["xhiveframework.rate_limiter.update", "xhiveframework.monitor.stop", "xhiveframework.recorder.dump"]

# Background Job Hooks
before_job = [
	"xhiveframework.monitor.start",
]
after_job = [
	"xhiveframework.monitor.stop",
	"xhiveframework.utils.file_lock.release_document_locks",
]
