"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatPhones = exports.formatEmails = void 0;
exports.formatUserIds = formatUserIds;
const crypto_1 = require("crypto");
const formatEmails = (email_addresses) => {
    const result = [];
    if (email_addresses) {
        email_addresses.forEach((email) => {
            result.push(hashAndEncode(email.toLowerCase()));
        });
    }
    return result;
};
exports.formatEmails = formatEmails;
const formatPhones = (phone_numbers) => {
    const result = [];
    if (!phone_numbers)
        return result;
    phone_numbers.forEach((phone) => {
        const validatedPhone = phone.match(/[0-9]{0,14}/g);
        if (validatedPhone === null) {
            throw new Error(`${phone} is not a valid E.164 phone number.`);
        }
        const formattedPhone = `+${phone.replace(/[^0-9]/g, '')}`;
        result.push(hashAndEncode(formattedPhone.substring(0, 15)));
    });
    return result;
};
exports.formatPhones = formatPhones;
function formatUserIds(userIds) {
    const result = [];
    if (userIds) {
        userIds.forEach((userId) => {
            result.push(hashAndEncode(userId.toLowerCase()));
        });
    }
    return result;
}
function hashAndEncode(property) {
    return (0, crypto_1.createHash)('sha256').update(property).digest('hex');
}
//# sourceMappingURL=formatter.js.map