# Copyright (c) 2024, JINGROW

from __future__ import unicode_literals

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


def execute():
	rename_pagetypes()
	rename_fields()


def rename_pagetypes():
	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_pagetype, to_pagetype in renames.items():
		if jingrow.db.table_exists(from_pagetype) and not jingrow.db.table_exists(to_pagetype):
			jingrow.rename_pg("PageType", from_pagetype, to_pagetype, force=True)


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

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