"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockHybxClient = void 0;
const payments = new Map();
class MockHybxClient {
    environment;
    constructor(environment = 'sandbox') {
        this.environment = environment;
    }
    async initiatePayment(request) {
        const paymentId = `mock-pay-${request.idempotencyKey.slice(0, 16)}`;
        const existing = payments.get(request.idempotencyKey);
        if (existing)
            return existing;
        const response = {
            paymentId,
            status: 'accepted',
            uetr: `mock-uetr-${paymentId}`,
            messageId: `mock-msg-${paymentId}`,
            createdAt: new Date().toISOString(),
            rawReference: request.endToEndId,
        };
        payments.set(request.idempotencyKey, response);
        payments.set(paymentId, response);
        return response;
    }
    async getPaymentStatus(paymentId) {
        const found = payments.get(paymentId);
        if (!found) {
            return {
                paymentId,
                status: 'pending',
                createdAt: new Date().toISOString(),
            };
        }
        return found;
    }
    async listSettlementEvents() {
        return Array.from(payments.values()).map((p) => ({
            eventId: `evt-${p.paymentId}`,
            paymentId: p.paymentId,
            status: p.status,
            settlementDate: new Date().toISOString().slice(0, 10),
            timestamp: new Date().toISOString(),
        }));
    }
    parseWebhookPayload(body) {
        const parsed = JSON.parse(body);
        return {
            eventType: String(parsed.eventType ?? 'payment.status'),
            eventId: String(parsed.eventId ?? `wh-${Date.now()}`),
            timestamp: String(parsed.timestamp ?? new Date().toISOString()),
            data: parsed.data ?? parsed,
        };
    }
}
exports.MockHybxClient = MockHybxClient;
