import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface RefreshTokenAuditLogAttributes {
	id: string;
	outbox_event_id?: string | null;
	request_id?: string | null;
	trace_id?: string | null;
	user_id?: string | null;
	session_id?: string | null;
	action: string;
	ip_address?: string | null;
	user_agent?: string | null;
	platform?: string | null;
	device_id?: string | null;
	previous_token_hash?: string | null;
	new_token_hash?: string | null;
	reason?: string | null;
	event_version?: number | null;
	created_at: Date;
}
export type RefreshTokenAuditLogPk = 'id' | 'created_at';
export type RefreshTokenAuditLogId = RefreshTokenAuditLog[RefreshTokenAuditLogPk];
export type RefreshTokenAuditLogOptionalAttributes =
	| 'id'
	| 'outbox_event_id'
	| 'request_id'
	| 'trace_id'
	| 'user_id'
	| 'session_id'
	| 'ip_address'
	| 'user_agent'
	| 'platform'
	| 'device_id'
	| 'previous_token_hash'
	| 'new_token_hash'
	| 'reason'
	| 'event_version'
	| 'created_at';
export type RefreshTokenAuditLogCreationAttributes = Optional<
	RefreshTokenAuditLogAttributes,
	RefreshTokenAuditLogOptionalAttributes
>;
export class RefreshTokenAuditLog
	extends Model<RefreshTokenAuditLogAttributes>
	implements RefreshTokenAuditLogAttributes
{
	declare id: string;
	declare outbox_event_id?: string | null;
	declare request_id?: string | null;
	declare trace_id?: string | null;
	declare user_id?: string | null;
	declare session_id?: string | null;
	declare action: string;
	declare ip_address?: string | null;
	declare user_agent?: string | null;
	declare platform?: string | null;
	declare device_id?: string | null;
	declare previous_token_hash?: string | null;
	declare new_token_hash?: string | null;
	declare reason?: string | null;
	declare event_version?: number | null;
	declare created_at: Date;
	// RefreshTokenAuditLog 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 RefreshTokenAuditLog {
		return RefreshTokenAuditLog.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				outbox_event_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				request_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				trace_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				user_id: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				session_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				action: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				ip_address: {
					type: DataTypes.INET,
					allowNull: true,
				},
				user_agent: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				platform: {
					type: DataTypes.STRING(50),
					allowNull: true,
				},
				device_id: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				previous_token_hash: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				new_token_hash: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				reason: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				event_version: {
					type: DataTypes.INTEGER,
					allowNull: true,
					defaultValue: 1,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: false,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
					primaryKey: true,
				},
			},
			{
				sequelize,
				tableName: 'refresh_token_audit_logs',
				schema: 'audit',
				timestamps: false,
			},
		);
	}
}
