import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { NotificationReceipt, NotificationReceiptId } from './NotificationReceipt';
export interface NotificationMessageAttributes {
	id: string;
	title: string;
	body?: string | null;
	type:
		| 'order_created'
		| 'payment_success'
		| 'payment_failed'
		| 'order_shipped'
		| 'order_delivered'
		| 'system_alert'
		| 'promotion'
		| 'chat_message'
		| 'security_alert'
		| 'account_update';
	data?: object | null;
	tenant_id?: string | null;
	scheduled_at?: Date | null;
	priority?: number | null;
	created_by?: string | null;
	campaign_id?: string | null;
	template_id?: string | null;
	external_key?: string | null;
	dedupe_key?: string | null;
	created_at?: Date | null;
	updated_at?: Date | null;
}
export type NotificationMessagePk = 'id';
export type NotificationMessageId = NotificationMessage[NotificationMessagePk];
export type NotificationMessageOptionalAttributes =
	| 'id'
	| 'body'
	| 'data'
	| 'tenant_id'
	| 'scheduled_at'
	| 'priority'
	| 'created_by'
	| 'campaign_id'
	| 'template_id'
	| 'external_key'
	| 'dedupe_key'
	| 'created_at'
	| 'updated_at';
export type NotificationMessageCreationAttributes = Optional<
	NotificationMessageAttributes,
	NotificationMessageOptionalAttributes
>;
export class NotificationMessage extends Model<NotificationMessageAttributes> implements NotificationMessageAttributes {
	declare id: string;
	declare title: string;
	declare body?: string | null;
	declare type:
		| 'order_created'
		| 'payment_success'
		| 'payment_failed'
		| 'order_shipped'
		| 'order_delivered'
		| 'system_alert'
		| 'promotion'
		| 'chat_message'
		| 'security_alert'
		| 'account_update';
	declare data?: object | null;
	declare tenant_id?: string | null;
	declare scheduled_at?: Date | null;
	declare priority?: number | null;
	declare created_by?: string | null;
	declare campaign_id?: string | null;
	declare template_id?: string | null;
	declare external_key?: string | null;
	declare dedupe_key?: string | null;
	declare created_at?: Date | null;
	declare updated_at?: Date | null;
	// NotificationMessage hasMany NotificationReceipt via message_id
	declare notification_receipts: NotificationReceipt[];
	declare getNotification_receipts: Sequelize.HasManyGetAssociationsMixin<NotificationReceipt>;
	declare setNotification_receipts: Sequelize.HasManySetAssociationsMixin<NotificationReceipt, NotificationReceiptId>;
	declare addNotification_receipt: Sequelize.HasManyAddAssociationMixin<NotificationReceipt, NotificationReceiptId>;
	declare addNotification_receipts: Sequelize.HasManyAddAssociationsMixin<NotificationReceipt, NotificationReceiptId>;
	declare createNotification_receipt: Sequelize.HasManyCreateAssociationMixin<NotificationReceipt>;
	declare removeNotification_receipt: Sequelize.HasManyRemoveAssociationMixin<
		NotificationReceipt,
		NotificationReceiptId
	>;
	declare removeNotification_receipts: Sequelize.HasManyRemoveAssociationsMixin<
		NotificationReceipt,
		NotificationReceiptId
	>;
	declare hasNotification_receipt: Sequelize.HasManyHasAssociationMixin<NotificationReceipt, NotificationReceiptId>;
	declare hasNotification_receipts: Sequelize.HasManyHasAssociationsMixin<NotificationReceipt, NotificationReceiptId>;
	declare countNotification_receipts: Sequelize.HasManyCountAssociationsMixin;
	static initModel(sequelize: Sequelize.Sequelize): typeof NotificationMessage {
		return NotificationMessage.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				title: {
					type: DataTypes.STRING(255),
					allowNull: false,
				},
				body: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				type: {
					type: DataTypes.ENUM(
						'order_created',
						'payment_success',
						'payment_failed',
						'order_shipped',
						'order_delivered',
						'system_alert',
						'promotion',
						'chat_message',
						'security_alert',
						'account_update',
					),
					allowNull: false,
				},
				data: {
					type: DataTypes.JSONB,
					allowNull: true,
				},
				tenant_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				scheduled_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				priority: {
					type: DataTypes.INTEGER,
					allowNull: true,
					defaultValue: 0,
				},
				created_by: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				campaign_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				template_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				external_key: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				dedupe_key: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'notification_messages',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_notification_messages_campaign_id',
						fields: [{ name: 'campaign_id' }],
					},
					{
						name: 'idx_notification_messages_dedupe_key',
						fields: [{ name: 'dedupe_key' }],
					},
					{
						name: 'idx_notification_messages_scheduled_at',
						fields: [{ name: 'scheduled_at' }],
					},
					{
						name: 'idx_notification_messages_tenant_type_created',
						fields: [{ name: 'tenant_id' }, { name: 'type' }, { name: 'created_at', order: 'DESC' }],
					},
					{
						name: 'idx_notification_messages_type',
						fields: [{ name: 'type' }],
					},
					{
						name: 'notification_messages_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
