import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { NotificationDeliveryAttempt, NotificationDeliveryAttemptId } from './NotificationDeliveryAttempt';
import type { User, UserId } from './User';
export interface NotificationDeviceAttributes {
	id: string;
	user_id: string;
	platform: 'web' | 'mobile' | 'zalo_miniapp' | 'internal';
	device_id: string;
	device_name?: string | null;
	device_info?: object | null;
	push_token?: string | null;
	one_signal_player_id?: string | null;
	is_active?: boolean | null;
	last_used_at?: Date | null;
	created_at?: Date | null;
	updated_at?: Date | null;
}
export type NotificationDevicePk = 'id';
export type NotificationDeviceId = NotificationDevice[NotificationDevicePk];
export type NotificationDeviceOptionalAttributes =
	| 'id'
	| 'device_name'
	| 'device_info'
	| 'push_token'
	| 'one_signal_player_id'
	| 'is_active'
	| 'last_used_at'
	| 'created_at'
	| 'updated_at';
export type NotificationDeviceCreationAttributes = Optional<
	NotificationDeviceAttributes,
	NotificationDeviceOptionalAttributes
>;
export class NotificationDevice extends Model<NotificationDeviceAttributes> implements NotificationDeviceAttributes {
	declare id: string;
	declare user_id: string;
	declare platform: 'web' | 'mobile' | 'zalo_miniapp' | 'internal';
	declare device_id: string;
	declare device_name?: string | null;
	declare device_info?: object | null;
	declare push_token?: string | null;
	declare one_signal_player_id?: string | null;
	declare is_active?: boolean | null;
	declare last_used_at?: Date | null;
	declare created_at?: Date | null;
	declare updated_at?: Date | null;
	// NotificationDevice hasMany NotificationDeliveryAttempt via device_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;
	// NotificationDevice 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 NotificationDevice {
		return NotificationDevice.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_devices_user_id_device_id_platform_key',
				},
				platform: {
					type: DataTypes.ENUM('web', 'mobile', 'zalo_miniapp', 'internal'),
					allowNull: false,
					unique: 'notification_devices_user_id_device_id_platform_key',
				},
				device_id: {
					type: DataTypes.STRING(255),
					allowNull: false,
					unique: 'notification_devices_user_id_device_id_platform_key',
				},
				device_name: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				device_info: {
					type: DataTypes.JSONB,
					allowNull: true,
				},
				push_token: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				one_signal_player_id: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				is_active: {
					type: DataTypes.BOOLEAN,
					allowNull: true,
					defaultValue: true,
				},
				last_used_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				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_devices',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_notification_devices_device_id',
						fields: [{ name: 'device_id' }],
					},
					{
						name: 'idx_notification_devices_push_token',
						unique: true,
						fields: [{ name: 'push_token' }],
					},
					{
						name: 'idx_notification_devices_user_id_is_active',
						fields: [{ name: 'user_id' }, { name: 'is_active' }],
					},
					{
						name: 'idx_notification_devices_user_id_platform',
						fields: [{ name: 'user_id' }, { name: 'platform' }],
					},
					{
						name: 'notification_devices_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'notification_devices_user_id_device_id_platform_key',
						unique: true,
						fields: [{ name: 'user_id' }, { name: 'device_id' }, { name: 'platform' }],
					},
				],
			},
		);
	}
}
