import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface NotificationTemplateAttributes {
	id: string;
	code: string;
	name: string;
	type: 'MARKETING' | 'BILLING' | 'SYSTEM_ALERT' | 'TRANSACTIONAL' | 'REMINDER' | 'ANNOUNCEMENT';
	channel: 'SMS' | 'EMAIL' | 'ZALO_ZNS' | 'ZALO_OA' | 'APP_PUSH' | 'IN_APP' | 'WEB_PUSH';
	content: string;
	subject?: string | null;
	description?: string | null;
	variables?: object | null;
	status: 'ACTIVE' | 'INACTIVE' | 'DRAFT';
	created_by?: string | null;
	updated_by?: string | null;
	created_at: Date;
	updated_at: Date;
}
export type NotificationTemplatePk = 'id';
export type NotificationTemplateId = NotificationTemplate[NotificationTemplatePk];
export type NotificationTemplateOptionalAttributes =
	| 'id'
	| 'subject'
	| 'description'
	| 'variables'
	| 'status'
	| 'created_by'
	| 'updated_by'
	| 'created_at'
	| 'updated_at';
export type NotificationTemplateCreationAttributes = Optional<
	NotificationTemplateAttributes,
	NotificationTemplateOptionalAttributes
>;
export class NotificationTemplate
	extends Model<NotificationTemplateAttributes>
	implements NotificationTemplateAttributes
{
	declare id: string;
	declare code: string;
	declare name: string;
	declare type: 'MARKETING' | 'BILLING' | 'SYSTEM_ALERT' | 'TRANSACTIONAL' | 'REMINDER' | 'ANNOUNCEMENT';
	declare channel: 'SMS' | 'EMAIL' | 'ZALO_ZNS' | 'ZALO_OA' | 'APP_PUSH' | 'IN_APP' | 'WEB_PUSH';
	declare content: string;
	declare subject?: string | null;
	declare description?: string | null;
	declare variables?: object | null;
	declare status: 'ACTIVE' | 'INACTIVE' | 'DRAFT';
	declare created_by?: string | null;
	declare updated_by?: string | null;
	declare created_at: Date;
	declare updated_at: Date;
	// NotificationTemplate belongsTo User via created_by
	declare created_by_user: User;
	declare getCreated_by_user: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setCreated_by_user: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createCreated_by_user: Sequelize.BelongsToCreateAssociationMixin<User>;
	// NotificationTemplate belongsTo User via updated_by
	declare updated_by_user: User;
	declare getUpdated_by_user: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setUpdated_by_user: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createUpdated_by_user: Sequelize.BelongsToCreateAssociationMixin<User>;
	static initModel(sequelize: Sequelize.Sequelize): typeof NotificationTemplate {
		return NotificationTemplate.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				code: {
					type: DataTypes.STRING(50),
					allowNull: false,
					unique: 'notification_templates_code_key',
				},
				name: {
					type: DataTypes.STRING(255),
					allowNull: false,
				},
				type: {
					type: DataTypes.ENUM('MARKETING', 'BILLING', 'SYSTEM_ALERT', 'TRANSACTIONAL', 'REMINDER', 'ANNOUNCEMENT'),
					allowNull: false,
				},
				channel: {
					type: DataTypes.ENUM('SMS', 'EMAIL', 'ZALO_ZNS', 'ZALO_OA', 'APP_PUSH', 'IN_APP', 'WEB_PUSH'),
					allowNull: false,
				},
				content: {
					type: DataTypes.TEXT,
					allowNull: false,
				},
				subject: {
					type: DataTypes.STRING(500),
					allowNull: true,
				},
				description: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				variables: {
					type: DataTypes.JSONB,
					allowNull: true,
				},
				status: {
					type: DataTypes.ENUM('ACTIVE', 'INACTIVE', 'DRAFT'),
					allowNull: false,
					defaultValue: 'ACTIVE',
				},
				created_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				updated_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'notification_templates',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_notification_templates_channel',
						fields: [{ name: 'channel' }],
					},
					{
						name: 'idx_notification_templates_created_at',
						fields: [{ name: 'created_at', order: 'DESC' }],
					},
					{
						name: 'idx_notification_templates_status',
						fields: [{ name: 'status' }],
					},
					{
						name: 'idx_notification_templates_type_status',
						fields: [{ name: 'type' }, { name: 'status' }],
					},
					{
						name: 'notification_templates_code_key',
						unique: true,
						fields: [{ name: 'code' }],
					},
					{
						name: 'notification_templates_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
