import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface EmailVerifyTokenAttributes {
	id: string;
	user_id: string;
	token_hash: string;
	expires_at: Date;
	used_at?: Date | null;
	created_at?: Date | null;
}
export type EmailVerifyTokenPk = 'id';
export type EmailVerifyTokenId = EmailVerifyToken[EmailVerifyTokenPk];
export type EmailVerifyTokenOptionalAttributes = 'id' | 'used_at' | 'created_at';
export type EmailVerifyTokenCreationAttributes = Optional<
	EmailVerifyTokenAttributes,
	EmailVerifyTokenOptionalAttributes
>;
export class EmailVerifyToken extends Model<EmailVerifyTokenAttributes> implements EmailVerifyTokenAttributes {
	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;
	// EmailVerifyToken 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 EmailVerifyToken {
		return EmailVerifyToken.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: 'email_verify_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: 'email_verify_tokens',
				schema: 'public',
				timestamps: false,
				indexes: [
					{
						name: 'email_verify_tokens_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'email_verify_tokens_token_hash_key',
						unique: true,
						fields: [{ name: 'token_hash' }],
					},
					{
						name: 'idx_email_verify_tokens_expires_at',
						fields: [{ name: 'expires_at' }],
					},
					{
						name: 'idx_email_verify_tokens_user_id',
						fields: [{ name: 'user_id' }],
					},
				],
			},
		);
	}
}
