# Copyright (c) 2015, InfluxFramework LLC and contributors
# For license information, please see license.txt


import influxframework
from dateutil.relativedelta import relativedelta
from influxframework.model.document import Document
from influxframework.utils import cint


class ManufacturingSettings(Document):
	pass


def get_mins_between_operations():
	return relativedelta(
		minutes=cint(influxframework.db.get_single_value("Manufacturing Settings", "mins_between_operations"))
		or 10
	)


@influxframework.whitelist()
def is_material_consumption_enabled():
	if not hasattr(influxframework.local, "material_consumption"):
		influxframework.local.material_consumption = cint(
			influxframework.db.get_single_value("Manufacturing Settings", "material_consumption")
		)

	return influxframework.local.material_consumption
