# Copyright (c) 2018, InfluxFramework LLC
# License: MIT. See LICENSE

import influxframework
from influxframework import _
from influxframework.model.document import Document
from influxframework.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):
			influxframework.throw(_("Page height and width cannot be zero"))

	def on_update(self):
		influxframework.clear_cache()


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

	return influxframework.local.enable_print_server
