import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface SystemAuditLogsDefaultAttributes {
	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 SystemAuditLogsDefaultPk = 'id' | 'created_at';
export type SystemAuditLogsDefaultId = SystemAuditLogsDefault[SystemAuditLogsDefaultPk];
export type SystemAuditLogsDefaultOptionalAttributes =
	| '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 SystemAuditLogsDefaultCreationAttributes = Optional<
	SystemAuditLogsDefaultAttributes,
	SystemAuditLogsDefaultOptionalAttributes
>;
export class SystemAuditLogsDefault
	extends Model<SystemAuditLogsDefaultAttributes>
	implements SystemAuditLogsDefaultAttributes
{
	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;
	// SystemAuditLogsDefault 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 SystemAuditLogsDefault {
		return SystemAuditLogsDefault.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				outbox_event_id: {
					type: DataTypes.UUID,
					allowNull: false,
					unique: 'system_audit_logs_default_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_default_outbox_event_id_created_at_key',
				},
			},
			{
				sequelize,
				tableName: 'system_audit_logs_default',
				schema: 'audit',
				timestamps: false,
				indexes: [
					{
						name: 'system_audit_logs_default_action_idx',
						fields: [{ name: 'action' }],
					},
					{
						name: 'system_audit_logs_default_actor_id_idx',
						fields: [{ name: 'actor_id' }],
					},
					{
						name: 'system_audit_logs_default_batch_id_idx',
						fields: [{ name: 'batch_id' }],
					},
					{
						name: 'system_audit_logs_default_created_at_idx',
						fields: [{ name: 'created_at', order: 'DESC' }],
					},
					{
						name: 'system_audit_logs_default_created_at_idx1',
						fields: [{ name: 'created_at' }],
					},
					{
						name: 'system_audit_logs_default_entity_type_entity_id_idx',
						fields: [{ name: 'entity_type' }, { name: 'entity_id' }],
					},
					{
						name: 'system_audit_logs_default_module_idx',
						fields: [{ name: 'module' }],
					},
					{
						name: 'system_audit_logs_default_outbox_event_id_created_at_key',
						unique: true,
						fields: [{ name: 'outbox_event_id' }, { name: 'created_at' }],
					},
					{
						name: 'system_audit_logs_default_pkey',
						unique: true,
						fields: [{ name: 'id' }, { name: 'created_at' }],
					},
					{
						name: 'system_audit_logs_default_request_id_idx',
						fields: [{ name: 'request_id' }],
					},
					{
						name: 'system_audit_logs_default_severity_idx',
						fields: [{ name: 'severity' }],
					},
					{
						name: 'system_audit_logs_default_tenant_id_idx',
						fields: [{ name: 'tenant_id' }],
					},
					{
						name: 'system_audit_logs_default_trace_id_idx',
						fields: [{ name: 'trace_id' }],
					},
				],
			},
		);
	}
}
