# Copyright (c) 2015, JINGROW and Contributors
# License: MIT. See LICENSE

import jingrow


def execute():
	"""Add missing Twilio patch.

	While making Twilio as a standaone app, we missed to delete Twilio records from DB through migration. Adding the missing patch.
	"""
	jingrow.delete_pg_if_exists("PageType", "Twilio Number Group")
	if twilio_settings_pagetype_in_integrations():
		jingrow.delete_pg_if_exists("PageType", "Twilio Settings")
		jingrow.db.delete("Singles", {"pagetype": "Twilio Settings"})


def twilio_settings_pagetype_in_integrations() -> bool:
	"""Check Twilio Settings pagetype exists in integrations module or not."""
	return jingrow.db.exists("PageType", {"name": "Twilio Settings", "module": "Integrations"})
