import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface UserPasswordHistoryAttributes {
	id: string;
	user_id: string;
	password_hash: string;
	changed_at?: Date | null;
	changed_by?: string | null;
	reason?: string | null;
}
export type UserPasswordHistoryPk = 'id';
export type UserPasswordHistoryId = UserPasswordHistory[UserPasswordHistoryPk];
export type UserPasswordHistoryOptionalAttributes = 'id' | 'changed_at' | 'changed_by' | 'reason';
export type UserPasswordHistoryCreationAttributes = Optional<
	UserPasswordHistoryAttributes,
	UserPasswordHistoryOptionalAttributes
>;
export class UserPasswordHistory extends Model<UserPasswordHistoryAttributes> implements UserPasswordHistoryAttributes {
	declare id: string;
	declare user_id: string;
	declare password_hash: string;
	declare changed_at?: Date | null;
	declare changed_by?: string | null;
	declare reason?: string | null;
	// UserPasswordHistory belongsTo User via changed_by
	declare changed_by_user: User;
	declare getChanged_by_user: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setChanged_by_user: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createChanged_by_user: Sequelize.BelongsToCreateAssociationMixin<User>;
	// UserPasswordHistory 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 UserPasswordHistory {
		return UserPasswordHistory.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				user_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				password_hash: {
					type: DataTypes.STRING(255),
					allowNull: false,
				},
				changed_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				changed_by: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				reason: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
			},
			{
				sequelize,
				tableName: 'user_password_history',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_user_password_history_changed_at',
						fields: [{ name: 'changed_at', order: 'DESC' }],
					},
					{
						name: 'idx_user_password_history_user_id',
						fields: [{ name: 'user_id' }],
					},
					{
						name: 'user_password_history_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
				],
			},
		);
	}
}
