import jingrow
from jingrow.query_builder.functions import Count
from jingrow.query_builder.terms import QueryBuilder


def check(base_query: QueryBuilder, document_name: str) -> bool:
	PressRole = jingrow.qb.DocType("Press Role")
	PressRoleResource = jingrow.qb.DocType("Press Role Resource")
	SiteBackup = jingrow.qb.DocType("Site Backup")
	return (
		base_query.left_join(PressRoleResource)
		.on(PressRoleResource.parent == PressRole.name)
		.left_join(SiteBackup)
		.on(SiteBackup.name == document_name)
		.select(Count(PressRole.name).as_("count"))
		.where(PressRoleResource.document_type == "Site")
		.where(PressRoleResource.document_name == SiteBackup.site)
		.run(as_dict=True)
		.pop()
		.get("count")
		> 0
	)
