# Copyright (c) 2015, JINGROW
# License: MIT. See LICENSE

import jingrow
from jingrow.model.page import Page


class EmailQueueRecipient(Page):
	# begin: auto-generated types
	# This code is auto-generated. Do not modify anything in this block.

	from typing import TYPE_CHECKING

	if TYPE_CHECKING:
		from jingrow.types import DF

		error: DF.Code | None
		parent: DF.Data
		parentfield: DF.Data
		parenttype: DF.Data
		recipient: DF.Data | None
		status: DF.Literal["", "Not Sent", "Sent"]
	# end: auto-generated types
	PAGETYPE = "Email Queue Recipient"

	def is_mail_to_be_sent(self):
		return self.status == "Not Sent"

	def is_mail_sent(self):
		return self.status == "Sent"

	def update_db(self, commit=False, **kwargs):
		jingrow.db.set_value(self.PAGETYPE, self.name, kwargs)
		if commit:
			jingrow.db.commit()


def on_pagetype_update():
	"""Index required for log clearing, modified is not indexed on child table by default"""
	jingrow.db.add_index("Email Queue Recipient", ["modified"])
