# Copyright (c) 2023, Jingrow and Contributors
# See license.txt

import typing

import jingrow
from jingrow.tests.utils import FrappeTestCase

if typing.TYPE_CHECKING:
	from jcloude.jcloude.doctype.app.app import App

from jcloude.jcloude.doctype.app.test_app import create_test_app
from jcloude.jcloude.doctype.release_group.test_release_group import (
	create_test_release_group,
)
from jcloude.jcloude.doctype.root_domain.test_root_domain import create_test_root_domain
from jcloude.jcloude.doctype.site_plan.test_site_plan import create_test_plan


def create_test_product_trial(
	app: "App",
):
	jingrow_app = create_test_app()
	trial_plan = create_test_plan("Site", is_trial_plan=True)
	domain = create_test_root_domain("local.fc.jingrow.dev")
	release_group = create_test_release_group([jingrow_app, app])
	product_trial = jingrow.get_pg(
		{
			"doctype": "Product Trial",
			"name": app.name,
			"title": app.title,
			"apps": [
				{
					"app": "jingrow",
				},
				{
					"app": app.name,
				},
			],
			"trial_plan": trial_plan.name,
			"domain": domain.name,
			"release_group": release_group.name,
			"email_subject": "Test Subject",
			"email_header_content": "Test Header",
		}
	).insert(ignore_if_duplicate=True)
	product_trial.reload()
	return product_trial


class TestProductTrial(FrappeTestCase):
	pass
