# Copyright (c) 2018, XhiveFramework Technologies and contributors
# License: MIT. See LICENSE

import xhiveframework
from xhiveframework import _
from xhiveframework.model.document import Document
from xhiveframework.utils import cint


class PrintSettings(Document):
	def validate(self):
		if self.pdf_page_size == "Custom" and not (self.pdf_page_height and self.pdf_page_width):
			xhiveframework.throw(_("Page height and width cannot be zero"))

	def on_update(self):
		xhiveframework.clear_cache()


@xhiveframework.whitelist()
def is_print_server_enabled():
	if not hasattr(xhiveframework.local, "enable_print_server"):
		xhiveframework.local.enable_print_server = cint(
			xhiveframework.db.get_single_value("Print Settings", "enable_print_server")
		)

	return xhiveframework.local.enable_print_server
