import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface PasswordResetTokenAttributes {
	id: string;
	user_id: string;
	token_hash: string;
	expires_at: Date;
	used_at?: Date | null;
	created_at?: Date | null;
}
export type PasswordResetTokenPk = 'id';
export type PasswordResetTokenId = PasswordResetToken[PasswordResetTokenPk];
export type PasswordResetTokenOptionalAttributes = 'id' | 'used_at' | 'created_at';
export type PasswordResetTokenCreationAttributes = Optional<
	PasswordResetTokenAttributes,
	PasswordResetTokenOptionalAttributes
>;
export class PasswordResetToken extends Model<PasswordResetTokenAttributes> implements PasswordResetTokenAttributes {
	declare id: string;
	declare user_id: string;
	declare token_hash: string;
	declare expires_at: Date;
	declare used_at?: Date | null;
	declare created_at?: Date | null;
	// PasswordResetToken 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 PasswordResetToken {
		return PasswordResetToken.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				user_id: {
					type: DataTypes.UUID,
					allowNull: false,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				token_hash: {
					type: DataTypes.CHAR(64),
					allowNull: false,
					unique: 'password_reset_tokens_token_hash_key',
				},
				expires_at: {
					type: DataTypes.DATE,
					allowNull: false,
				},
				used_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'password_reset_tokens',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'idx_password_reset_tokens_expires_at',
						fields: [{ name: 'expires_at' }],
					},
					{
						name: 'idx_password_reset_tokens_user_id',
						fields: [{ name: 'user_id' }],
					},
					{
						name: 'password_reset_tokens_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'password_reset_tokens_token_hash_key',
						unique: true,
						fields: [{ name: 'token_hash' }],
					},
				],
			},
		);
	}
}
