"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EMAIL_SELECTOR_ATTRIBUTES = void 0;
exports.normalizeEmailAttributes = normalizeEmailAttributes;
exports.buildEmailSelectorPrototype = buildEmailSelectorPrototype;
exports.getEmailUrl = getEmailUrl;
exports.EMAIL_SELECTOR_ATTRIBUTES = [
    'from',
    'subject',
    'body_text',
    'to_received',
];
function normalizeEmailAttributes(email) {
    return reduceEmailSelectorAttributes(email.input_properties, true);
}
function buildEmailSelectorPrototype(email, includeToReceived, excludedAttributes) {
    return {
        selector_type: 'email',
        ...reduceEmailSelectorAttributes(email.input_properties, includeToReceived, excludedAttributes),
    };
}
function reduceEmailSelectorAttributes(email, includeToReceived, excludedAttributes) {
    const selectorAttributes = exports.EMAIL_SELECTOR_ATTRIBUTES.filter((attribute) => !excludedAttributes?.includes(attribute)).filter((attribute) => includeToReceived || attribute !== 'to_received');
    return Object.entries(email).reduce((acc, [key, value]) => {
        if (selectorAttributes.includes(key)) {
            acc[key] = value;
        }
        return acc;
    }, {});
}
function getEmailUrl(email) {
    return (email.input_artifacts.body_html_uri || email.input_artifacts.body_text_uri);
}
