import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
export interface AuditDeadLetterAttributes {
	id: string;
	original_event_id: string;
	event_type: string;
	original_payload: object;
	error_message: string;
	error_stack?: string | null;
	failed_at?: Date | null;
	replayed?: boolean | null;
	replayed_at?: Date | null;
	replay_count?: number | null;
	investigation_status?: string | null;
	resolution_notes?: string | null;
	created_at?: Date | null;
}
export type AuditDeadLetterPk = 'id';
export type AuditDeadLetterId = AuditDeadLetter[AuditDeadLetterPk];
export type AuditDeadLetterOptionalAttributes =
	| 'id'
	| 'error_stack'
	| 'failed_at'
	| 'replayed'
	| 'replayed_at'
	| 'replay_count'
	| 'investigation_status'
	| 'resolution_notes'
	| 'created_at';
export type AuditDeadLetterCreationAttributes = Optional<AuditDeadLetterAttributes, AuditDeadLetterOptionalAttributes>;
export class AuditDeadLetter extends Model<AuditDeadLetterAttributes> implements AuditDeadLetterAttributes {
	declare id: string;
	declare original_event_id: string;
	declare event_type: string;
	declare original_payload: object;
	declare error_message: string;
	declare error_stack?: string | null;
	declare failed_at?: Date | null;
	declare replayed?: boolean | null;
	declare replayed_at?: Date | null;
	declare replay_count?: number | null;
	declare investigation_status?: string | null;
	declare resolution_notes?: string | null;
	declare created_at?: Date | null;
	static initModel(sequelize: Sequelize.Sequelize): typeof AuditDeadLetter {
		return AuditDeadLetter.init(
			{
				id: {
					type: DataTypes.UUID,
					allowNull: false,
					defaultValue: DataTypes.UUIDV4,
					primaryKey: true,
				},
				original_event_id: {
					type: DataTypes.UUID,
					allowNull: false,
				},
				event_type: {
					type: DataTypes.STRING(50),
					allowNull: false,
				},
				original_payload: {
					type: DataTypes.JSONB,
					allowNull: false,
				},
				error_message: {
					type: DataTypes.TEXT,
					allowNull: false,
				},
				error_stack: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				failed_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
				replayed: {
					type: DataTypes.BOOLEAN,
					allowNull: true,
					defaultValue: false,
				},
				replayed_at: {
					type: DataTypes.DATE,
					allowNull: true,
				},
				replay_count: {
					type: DataTypes.INTEGER,
					allowNull: true,
					defaultValue: 0,
				},
				investigation_status: {
					type: DataTypes.STRING(50),
					allowNull: true,
					defaultValue: 'PENDING',
				},
				resolution_notes: {
					type: DataTypes.TEXT,
					allowNull: true,
				},
				created_at: {
					type: DataTypes.DATE,
					allowNull: true,
					defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
				},
			},
			{
				sequelize,
				tableName: 'audit_dead_letter',
				schema: 'audit',
				timestamps: false,
				indexes: [
					{
						name: 'audit_dead_letter_pkey',
						unique: true,
						fields: [{ name: 'id' }],
					},
					{
						name: 'idx_dead_letter_event_type',
						fields: [{ name: 'event_type' }],
					},
					{
						name: 'idx_dead_letter_failed_at',
						fields: [{ name: 'failed_at', order: 'DESC' }],
					},
					{
						name: 'idx_dead_letter_investigation_status',
						fields: [{ name: 'investigation_status' }],
					},
					{
						name: 'idx_dead_letter_replayed',
						fields: [{ name: 'replayed' }, { name: 'failed_at' }],
					},
				],
			},
		);
	}
}
