import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface AuthAuditLogAttributes {
	id: string;
	outbox_event_id?: string | null;
	request_id?: string | null;
	trace_id?: string | null;
	user_id?: string | null;
	action: string;
	ip_address?: string | null;
	user_agent?: string | null;
	device_info?: object | null;
	success?: boolean | null;
	failure_reason?: string | null;
	session_id?: string | null;
	event_version?: number | null;
	created_at: Date;
}
export type AuthAuditLogPk = 'id' | 'created_at';
export type AuthAuditLogId = AuthAuditLog[AuthAuditLogPk];
export type AuthAuditLogOptionalAttributes =
	| 'id'
	| 'outbox_event_id'
	| 'request_id'
	| 'trace_id'
	| 'user_id'
	| 'ip_address'
	| 'user_agent'
	| 'device_info'
	| 'success'
	| 'failure_reason'
	| 'session_id'
	| 'event_version'
	| 'created_at';
export type AuthAuditLogCreationAttributes = Optional<AuthAuditLogAttributes, AuthAuditLogOptionalAttributes>;
export class AuthAuditLog extends Model<AuthAuditLogAttributes> implements AuthAuditLogAttributes {
	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 action: string;
	declare ip_address?: string | null;
	declare user_agent?: string | null;
	declare device_info?: object | null;
	declare success?: boolean | null;
	declare failure_reason?: string | null;
	declare session_id?: string | null;
	declare event_version?: number | null;
	declare created_at: Date;
	// AuthAuditLog 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 AuthAuditLog {
		return AuthAuditLog.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',
					},
				},
				action: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				ip_address: {
					type: DataTypes.INET,
					allowNull: true,
				},
				user_agent: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				device_info: {
					type: DataTypes.JSONB,
					allowNull: true,
				},
				success: {
					type: DataTypes.BOOLEAN,
					allowNull: true,
					defaultValue: true,
				},
				failure_reason: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				session_id: {
					type: DataTypes.UUID,
					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: 'auth_audit_logs',
				schema: 'audit',
				timestamps: false,
			},
		);
	}
}
