import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { NotificationDeliveryAttempt, NotificationDeliveryAttemptId } from './NotificationDeliveryAttempt';
import type { NotificationMessage, NotificationMessageId } from './NotificationMessage';
import type { User, UserId } from './User';
export interface NotificationReceiptAttributes {
	id: string;
	message_id: string;
	user_id: string;
	channel: 'in_app' | 'push' | 'email' | 'sms' | 'zalo';
	read_at?: Date | null;
	deleted_at?: Date | null;
	archived_at?: Date | null;
	created_at?: Date | null;
	updated_at?: Date | null;
}
export type NotificationReceiptPk = 'id';
export type NotificationReceiptId = NotificationReceipt[NotificationReceiptPk];
export type NotificationReceiptOptionalAttributes =
	| 'id'
	| 'read_at'
	| 'deleted_at'
	| 'archived_at'
	| 'created_at'
	| 'updated_at';
export type NotificationReceiptCreationAttributes = Optional<
	NotificationReceiptAttributes,
	NotificationReceiptOptionalAttributes
>;
export class NotificationReceipt extends Model<NotificationReceiptAttributes> implements NotificationReceiptAttributes {
	declare id: string;
	declare message_id: string;
	declare user_id: string;
	declare channel: 'in_app' | 'push' | 'email' | 'sms' | 'zalo';
	declare read_at?: Date | null;
	declare deleted_at?: Date | null;
	declare archived_at?: Date | null;
	declare created_at?: Date | null;
	declare updated_at?: Date | null;
	// NotificationReceipt belongsTo NotificationMessage via message_id
	declare message: NotificationMessage;
	declare getMessage: Sequelize.BelongsToGetAssociationMixin<NotificationMessage>;
	declare setMessage: Sequelize.BelongsToSetAssociationMixin<NotificationMessage, NotificationMessageId>;
	declare createMessage: Sequelize.BelongsToCreateAssociationMixin<NotificationMessage>;
	// NotificationReceipt hasMany NotificationDeliveryAttempt via receipt_id
	declare notification_delivery_attempts: NotificationDeliveryAttempt[];
	declare getNotification_delivery_attempts: Sequelize.HasManyGetAssociationsMixin<NotificationDeliveryAttempt>;
	declare setNotification_delivery_attempts: Sequelize.HasManySetAssociationsMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare addNotification_delivery_attempt: Sequelize.HasManyAddAssociationMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare addNotification_delivery_attempts: Sequelize.HasManyAddAssociationsMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare createNotification_delivery_attempt: Sequelize.HasManyCreateAssociationMixin<NotificationDeliveryAttempt>;
	declare removeNotification_delivery_attempt: Sequelize.HasManyRemoveAssociationMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare removeNotification_delivery_attempts: Sequelize.HasManyRemoveAssociationsMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare hasNotification_delivery_attempt: Sequelize.HasManyHasAssociationMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare hasNotification_delivery_attempts: Sequelize.HasManyHasAssociationsMixin<
		NotificationDeliveryAttempt,
		NotificationDeliveryAttemptId
	>;
	declare countNotification_delivery_attempts: Sequelize.HasManyCountAssociationsMixin;
	// NotificationReceipt belongsTo User via user_id
	declare user: User;
	declare getUser: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setUser: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createUser: Sequelize.BelongsToCreateAssociationMixin<User>;
	static initModel(sequelize: Sequelize.Sequelize): typeof NotificationReceipt {
		return NotificationReceipt.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				message_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'notification_messages',
						key: 'id',
					},
					unique: 'notification_receipts_message_id_user_id_channel_key',
				},
				user_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'users',
						key: 'id',
					},
					unique: 'notification_receipts_message_id_user_id_channel_key',
				},
				channel: {
					type: DataTypes.ENUM('in_app', 'push', 'email', 'sms', 'zalo'),
					allowNull: false,
					unique: 'notification_receipts_message_id_user_id_channel_key',
				},
				read_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				deleted_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				archived_at: {
					type: DataTypes.DATE,
					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_receipts',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_notification_receipts_channel',
						fields: [{ name: 'channel' }],
					},
					{
						name: 'idx_notification_receipts_message_id',
						fields: [{ name: 'message_id' }],
					},
					{
						name: 'idx_notification_receipts_unread',
						fields: [{ name: 'user_id' }, { name: 'created_at', order: 'DESC' }],
					},
					{
						name: 'idx_notification_receipts_user_id',
						fields: [{ name: 'user_id' }],
					},
					{
						name: 'notification_receipts_message_id_user_id_channel_key',
						unique: true,
						fields: [{ name: 'message_id' }, { name: 'user_id' }, { name: 'channel' }],
					},
					{
						name: 'notification_receipts_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
