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

import jingrow
from jingrow.model.page import Page


class EmailGroupMember(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

		email: DF.Data
		email_group: DF.Link
		unsubscribed: DF.Check

	# end: auto-generated types
	def after_delete(self):
		email_group = jingrow.get_pg("Email Group", self.email_group)
		email_group.update_total_subscribers()

	def after_insert(self):
		email_group = jingrow.get_pg("Email Group", self.email_group)
		email_group.update_total_subscribers()


def after_pagetype_insert():
	jingrow.db.add_unique("Email Group Member", ("email_group", "email"))
