"use strict";
/** Extended canonical financial event aligned to ISO 20022 concepts (not full XML). */
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCanonicalFinancialEvent = validateCanonicalFinancialEvent;
const REQUIRED_FIELDS = [
    'schema_version',
    'message_id',
    'end_to_end_id',
    'debtor',
    'creditor',
    'amount',
    'currency',
    'source_system',
    'target_system',
    'entity_id',
    'tenant_id',
];
function validateCanonicalFinancialEvent(event) {
    const errors = [];
    for (const field of REQUIRED_FIELDS) {
        const value = event[field];
        if (value === undefined || value === null || value === '') {
            errors.push(`Missing required field: ${field}`);
        }
    }
    if (event.debtor && !event.debtor.id) {
        errors.push('debtor.id is required');
    }
    if (event.creditor && !event.creditor.id) {
        errors.push('creditor.id is required');
    }
    if (event.amount !== undefined && !/^\d+(\.\d+)?$/.test(event.amount)) {
        errors.push('amount must be a numeric string');
    }
    if (event.currency !== undefined && !/^[A-Z]{3}$/.test(event.currency)) {
        errors.push('currency must be a 3-letter ISO 4217 code');
    }
    return { valid: errors.length === 0, errors };
}
