# Copyright (c) 2024, Jingrow Technologies Pvt. Ltd. and Contributors

from __future__ import unicode_literals

import jingrow
from jingrow.model.utils.rename_field import rename_field


def execute():
	rename_doctypes()
	rename_fields()


def rename_doctypes():
	renames = {
		"SaaS Product": "Product Trial",
		"SaaS Product App": "Product Trial App",
		"SaaS Product Signup Field": "Product Trial Signup Field",
		"SaaS Product Site Request": "Product Trial Request",
	}
	for from_doctype, to_doctype in renames.items():
		if jingrow.db.table_exists(from_doctype) and not jingrow.db.table_exists(to_doctype):
			jingrow.rename_pg("DocType", from_doctype, to_doctype, force=True)


def rename_fields():
	jingrow.reload_doctype("Account Request")
	rename_field("Account Request", "saas_product", "product_trial")

	jingrow.reload_doctype("Product Trial Request")
	rename_field("Product Trial Request", "saas_product", "product_trial")
