import { logger } from '@/infrastructure/monitoring/logger';

export interface CanonicalEvent {
	eventId: string;
	txnId: string;
	eventType: string;
	eventTime: string;
	producerService: string;
	payload?: Record<string, unknown>;
}

/**
 * dbis.data.event-store
 * Append-only canonical event store (scaffold, in-memory for now).
 */
export class EventStoreService {
	private readonly events: CanonicalEvent[] = [];

	append(event: CanonicalEvent): void {
		this.events.push(event);
		logger.info('EventStoreService.append', { eventType: event.eventType, txnId: event.txnId });
	}

	replay(fromIndex = 0): CanonicalEvent[] {
		return this.events.slice(fromIndex);
	}
}

export const eventStoreService = new EventStoreService();

