import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface SystemAuditLogAttributes {
	id: string;
	outbox_event_id: string;
	request_id: string;
	trace_id: string;
	session_id?: string | null;
	tenant_id?: string | null;
	actor_id?: string | null;
	actor_name?: string | null;
	actor_email?: string | null;
	actor_role?: string | null;
	action: string;
	module: string;
	entity_id?: string | null;
	entity_type?: string | null;
	batch_id?: string | null;
	description?: string | null;
	severity?: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL' | null;
	ip_address?: string | null;
	user_agent?: string | null;
	payload?: object | null;
	payload_size?: number | null;
	success?: boolean | null;
	failure_reason?: string | null;
	event_version?: number | null;
	created_at: Date;
}
export type SystemAuditLogPk = 'id' | 'created_at';
export type SystemAuditLogId = SystemAuditLog[SystemAuditLogPk];
export type SystemAuditLogOptionalAttributes =
	| 'id'
	| 'session_id'
	| 'tenant_id'
	| 'actor_id'
	| 'actor_name'
	| 'actor_email'
	| 'actor_role'
	| 'entity_id'
	| 'entity_type'
	| 'batch_id'
	| 'description'
	| 'severity'
	| 'ip_address'
	| 'user_agent'
	| 'payload'
	| 'payload_size'
	| 'success'
	| 'failure_reason'
	| 'event_version'
	| 'created_at';
export type SystemAuditLogCreationAttributes = Optional<SystemAuditLogAttributes, SystemAuditLogOptionalAttributes>;
export class SystemAuditLog extends Model<SystemAuditLogAttributes> implements SystemAuditLogAttributes {
	declare id: string;
	declare outbox_event_id: string;
	declare request_id: string;
	declare trace_id: string;
	declare session_id?: string | null;
	declare tenant_id?: string | null;
	declare actor_id?: string | null;
	declare actor_name?: string | null;
	declare actor_email?: string | null;
	declare actor_role?: string | null;
	declare action: string;
	declare module: string;
	declare entity_id?: string | null;
	declare entity_type?: string | null;
	declare batch_id?: string | null;
	declare description?: string | null;
	declare severity?: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL' | null;
	declare ip_address?: string | null;
	declare user_agent?: string | null;
	declare payload?: object | null;
	declare payload_size?: number | null;
	declare success?: boolean | null;
	declare failure_reason?: string | null;
	declare event_version?: number | null;
	declare created_at: Date;
	// SystemAuditLog belongsTo User via actor_id
	declare actor: User;
	declare getActor: Sequelize.BelongsToGetAssociationMixin<User>;
	declare setActor: Sequelize.BelongsToSetAssociationMixin<User, UserId>;
	declare createActor: Sequelize.BelongsToCreateAssociationMixin<User>;
	static initModel(sequelize: Sequelize.Sequelize): typeof SystemAuditLog {
		return SystemAuditLog.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				outbox_event_id: {
					type: DataTypes.UUID,
					allowNull: false,
					unique: 'system_audit_logs_outbox_event_id_created_at_key',
				},
				request_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				trace_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				session_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				tenant_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				actor_id: {
					type: DataTypes.UUID,
					allowNull: true,
					references: {
						model: 'users',
						key: 'id',
					},
				},
				actor_name: {
					type: DataTypes.STRING(200),
					allowNull: true,
				},
				actor_email: {
					type: DataTypes.STRING(255),
					allowNull: true,
				},
				actor_role: {
					type: DataTypes.STRING(50),
					allowNull: true,
				},
				action: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				module: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				entity_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				entity_type: {
					type: DataTypes.STRING(50),
					allowNull: true,
				},
				batch_id: {
					type: DataTypes.UUID,
					allowNull: true,
				},
				description: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				severity: {
					type: DataTypes.ENUM('LOW', 'MEDIUM', 'HIGH', 'CRITICAL'),
					allowNull: true,
					defaultValue: 'LOW',
				},
				ip_address: {
					type: DataTypes.INET,
					allowNull: true,
				},
				user_agent: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				payload: {
					type: DataTypes.JSONB,
					allowNull: true,
				},
				payload_size: {
					type: DataTypes.INTEGER,
					allowNull: true,
				},
				success: {
					type: DataTypes.BOOLEAN,
					allowNull: true,
					defaultValue: true,
				},
				failure_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,
					unique: 'system_audit_logs_outbox_event_id_created_at_key',
				},
			},
			{
				sequelize,
				tableName: 'system_audit_logs',
				schema: 'audit',
				timestamps: false,
			},
		);
	}
}
