import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface NotificationPreferenceAttributes {
	id: string;
	user_id: string;
	notification_type:
		| 'order_created'
		| 'payment_success'
		| 'payment_failed'
		| 'order_shipped'
		| 'order_delivered'
		| 'system_alert'
		| 'promotion'
		| 'chat_message'
		| 'security_alert'
		| 'account_update';
	channel: 'in_app' | 'push' | 'email' | 'sms' | 'zalo';
	is_enabled?: boolean | null;
	quiet_hours_start?: string | null;
	quiet_hours_end?: string | null;
	timezone?: string | null;
	created_at?: Date | null;
	updated_at?: Date | null;
}
export type NotificationPreferencePk = 'id';
export type NotificationPreferenceId = NotificationPreference[NotificationPreferencePk];
export type NotificationPreferenceOptionalAttributes =
	| 'id'
	| 'is_enabled'
	| 'quiet_hours_start'
	| 'quiet_hours_end'
	| 'timezone'
	| 'created_at'
	| 'updated_at';
export type NotificationPreferenceCreationAttributes = Optional<
	NotificationPreferenceAttributes,
	NotificationPreferenceOptionalAttributes
>;
export class NotificationPreference
	extends Model<NotificationPreferenceAttributes>
	implements NotificationPreferenceAttributes
{
	declare id: string;
	declare user_id: string;
	declare notification_type:
		| 'order_created'
		| 'payment_success'
		| 'payment_failed'
		| 'order_shipped'
		| 'order_delivered'
		| 'system_alert'
		| 'promotion'
		| 'chat_message'
		| 'security_alert'
		| 'account_update';
	declare channel: 'in_app' | 'push' | 'email' | 'sms' | 'zalo';
	declare is_enabled?: boolean | null;
	declare quiet_hours_start?: string | null;
	declare quiet_hours_end?: string | null;
	declare timezone?: string | null;
	declare created_at?: Date | null;
	declare updated_at?: Date | null;
	// NotificationPreference 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 NotificationPreference {
		return NotificationPreference.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				user_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'users',
						key: 'id',
					},
					unique: 'notification_preferences_user_id_notification_type_channel_key',
				},
				notification_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,
					unique: 'notification_preferences_user_id_notification_type_channel_key',
				},
				channel: {
					type: DataTypes.ENUM('in_app', 'push', 'email', 'sms', 'zalo'),
					allowNull: false,
					unique: 'notification_preferences_user_id_notification_type_channel_key',
				},
				is_enabled: {
					type: DataTypes.BOOLEAN,
					allowNull: true,
					defaultValue: true,
				},
				quiet_hours_start: {
					type: DataTypes.TIME,
					allowNull: true,
				},
				quiet_hours_end: {
					type: DataTypes.TIME,
					allowNull: true,
				},
				timezone: {
					type: DataTypes.STRING(50),
					allowNull: true,
					defaultValue: 'Asia\/Ho_Chi_Minh',
				},
				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_preferences',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_notification_prefs_enabled',
						fields: [{ name: 'is_enabled' }],
					},
					{
						name: 'idx_notification_prefs_type',
						fields: [{ name: 'notification_type' }],
					},
					{
						name: 'idx_notification_prefs_user_id',
						fields: [{ name: 'user_id' }],
					},
					{
						name: 'notification_preferences_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'notification_preferences_user_id_notification_type_channel_key',
						unique: true,
						fields: [{ name: 'user_id' }, { name: 'notification_type' }, { name: 'channel' }],
					},
				],
			},
		);
	}
}
