import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { User, UserId } from './User';
export interface EntityChangeLogsDefaultAttributes {
	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 EntityChangeLogsDefaultPk = 'id' | 'created_at';
export type EntityChangeLogsDefaultId = EntityChangeLogsDefault[EntityChangeLogsDefaultPk];
export type EntityChangeLogsDefaultOptionalAttributes =
	| 'id'
	| 'actor_id'
	| 'actor_name'
	| 'actor_email'
	| 'payload_size'
	| 'reason'
	| 'event_version'
	| 'created_at';
export type EntityChangeLogsDefaultCreationAttributes = Optional<
	EntityChangeLogsDefaultAttributes,
	EntityChangeLogsDefaultOptionalAttributes
>;
export class EntityChangeLogsDefault
	extends Model<EntityChangeLogsDefaultAttributes>
	implements EntityChangeLogsDefaultAttributes
{
	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;
	// EntityChangeLogsDefault 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 EntityChangeLogsDefault {
		return EntityChangeLogsDefault.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				outbox_event_id: {
					type: DataTypes.UUID,
					allowNull: false,
					unique: 'entity_change_logs_default_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_default_outbox_event_id_created_at_key',
				},
			},
			{
				sequelize,
				tableName: 'entity_change_logs_default',
				schema: 'audit',
				timestamps: false,
				indexes: [
					{
						name: 'entity_change_logs_default_change_type_idx',
						fields: [{ name: 'change_type' }],
					},
					{
						name: 'entity_change_logs_default_created_at_idx',
						fields: [{ name: 'created_at', order: 'DESC' }],
					},
					{
						name: 'entity_change_logs_default_created_at_idx1',
						fields: [{ name: 'created_at' }],
					},
					{
						name: 'entity_change_logs_default_entity_type_entity_id_idx',
						fields: [{ name: 'entity_type' }, { name: 'entity_id' }],
					},
					{
						name: 'entity_change_logs_default_outbox_event_id_created_at_key',
						unique: true,
						fields: [{ name: 'outbox_event_id' }, { name: 'created_at' }],
					},
					{
						name: 'entity_change_logs_default_pkey',
						unique: true,
						fields: [{ name: 'id' }, { name: 'created_at' }],
					},
					{
						name: 'entity_change_logs_default_request_id_idx',
						fields: [{ name: 'request_id' }],
					},
				],
			},
		);
	}
}
