import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface EntityChangeLogAttributes {
	id: string;
	outbox_event_id: string;
	request_id: string;
	trace_id: string;
	entity_type: string;
	entity_id: string;
	actor_id?: string | null;
	actor_name?: string | null;
	actor_email?: string | null;
	change_type: string;
	payload: object;
	payload_size?: number | null;
	reason?: string | null;
	event_version?: number | null;
	created_at: Date;
}
export type EntityChangeLogPk = 'id' | 'created_at';
export type EntityChangeLogId = EntityChangeLog[EntityChangeLogPk];
export type EntityChangeLogOptionalAttributes =
	| 'id'
	| 'actor_id'
	| 'actor_name'
	| 'actor_email'
	| 'payload_size'
	| 'reason'
	| 'event_version'
	| 'created_at';
export type EntityChangeLogCreationAttributes = Optional<EntityChangeLogAttributes, EntityChangeLogOptionalAttributes>;
export class EntityChangeLog extends Model<EntityChangeLogAttributes> implements EntityChangeLogAttributes {
	declare id: string;
	declare outbox_event_id: string;
	declare request_id: string;
	declare trace_id: string;
	declare entity_type: string;
	declare entity_id: string;
	declare actor_id?: string | null;
	declare actor_name?: string | null;
	declare actor_email?: string | null;
	declare change_type: string;
	declare payload: object;
	declare payload_size?: number | null;
	declare reason?: string | null;
	declare event_version?: number | null;
	declare created_at: Date;
	// EntityChangeLog 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 EntityChangeLog {
		return EntityChangeLog.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				outbox_event_id: {
					type: DataTypes.UUID,
					allowNull: false,
					unique: 'entity_change_logs_outbox_event_id_created_at_key',
				},
				request_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				trace_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				entity_type: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				entity_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				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,
				},
				change_type: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				payload: {
					type: DataTypes.JSONB,
					allowNull: false,
				},
				payload_size: {
					type: DataTypes.INTEGER,
					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,
					unique: 'entity_change_logs_outbox_event_id_created_at_key',
				},
			},
			{
				sequelize,
				tableName: 'entity_change_logs',
				schema: 'audit',
				timestamps: false,
			},
		);
	}
}
