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

/**
 * dbis.edge.message-gateway
 * Terminates file/MQ/SFTP/AS2/AS4 envelopes. Validates and forwards to Inbox.
 */
export class MessageGatewayService {
	async acceptPayload(params: {
		rail: string;
		payload: string | Buffer;
		signature?: string;
		metadata?: Record<string, unknown>;
	}): Promise<{ status: 'ACCEPTED' | 'REJECTED'; reason?: string; fingerprint?: string }> {
		// TODO: envelope validation/signature verification per rail
		const fingerprint = `fp-${Date.now()}-${Math.random().toString(36).slice(2)}`;
		logger.info('MessageGatewayService.acceptPayload', {
			rail: params.rail,
			size: typeof params.payload === 'string' ? params.payload.length : params.payload.byteLength,
			fingerprint,
		});
		return { status: 'ACCEPTED', fingerprint };
	}
}

export const messageGatewayService = new MessageGatewayService();

