import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
export interface AuditOutboxAttributes {
	id: string;
	request_id: string;
	trace_id: string;
	event_type: string;
	payload: object;
	payload_size?: number | null;
	status?: string | null;
	processed_at?: Date | null;
	error_message?: string | null;
	retry_count?: number | null;
	max_retries?: number | null;
	failed_at?: Date | null;
	created_at?: Date | null;
	updated_at?: Date | null;
}
export type AuditOutboxPk = 'id';
export type AuditOutboxId = AuditOutbox[AuditOutboxPk];
export type AuditOutboxOptionalAttributes =
	| 'id'
	| 'payload_size'
	| 'status'
	| 'processed_at'
	| 'error_message'
	| 'retry_count'
	| 'max_retries'
	| 'failed_at'
	| 'created_at'
	| 'updated_at';
export type AuditOutboxCreationAttributes = Optional<AuditOutboxAttributes, AuditOutboxOptionalAttributes>;
export class AuditOutbox extends Model<AuditOutboxAttributes> implements AuditOutboxAttributes {
	declare id: string;
	declare request_id: string;
	declare trace_id: string;
	declare event_type: string;
	declare payload: object;
	declare payload_size?: number | null;
	declare status?: string | null;
	declare processed_at?: Date | null;
	declare error_message?: string | null;
	declare retry_count?: number | null;
	declare max_retries?: number | null;
	declare failed_at?: Date | null;
	declare created_at?: Date | null;
	declare updated_at?: Date | null;
	static initModel(sequelize: Sequelize.Sequelize): typeof AuditOutbox {
		return AuditOutbox.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				request_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				trace_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				event_type: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				payload: {
					type: DataTypes.JSONB,
					allowNull: false,
				},
				payload_size: {
					type: DataTypes.INTEGER,
					allowNull: true,
				},
				status: {
					type: DataTypes.STRING(20),
					allowNull: true,
					defaultValue: 'PENDING',
				},
				processed_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				error_message: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				retry_count: {
					type: DataTypes.INTEGER,
					allowNull: true,
					defaultValue: 0,
				},
				max_retries: {
					type: DataTypes.INTEGER,
					allowNull: true,
					defaultValue: 3,
				},
				failed_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				updated_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'audit_outbox',
				schema: 'audit',
				timestamps: false,
				indexes: [
					{
						name: 'audit_outbox_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'idx_audit_outbox_pending_created',
						fields: [{ name: 'status' }, { name: 'created_at' }],
					},
					{
						name: 'idx_audit_outbox_processing',
						fields: [{ name: 'status' }, { name: 'updated_at' }],
					},
					{
						name: 'idx_audit_outbox_retry',
						fields: [{ name: 'status' }, { name: 'retry_count' }],
					},
					{
						name: 'idx_audit_outbox_status',
						fields: [{ name: 'status' }],
					},
					{
						name: 'idx_audit_outbox_status_created',
						fields: [{ name: 'status' }, { name: 'created_at' }],
					},
				],
			},
		);
	}
}
