"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLastEmail = void 0;
const lodash_1 = require("lodash");
const getLastEmail = (emails) => {
    if ((0, lodash_1.isNil)(emails))
        return undefined;
    /**
     * Filter out emails without a deleted_date
     */
    const availableEmails = emails.filter((email) => (0, lodash_1.isNil)(email.deleted_date) || (0, lodash_1.isEmpty)(email.deleted_date));
    /**
     * According to Elation's documentation there is only only 1 email with empty deleted_date
     */
    if (availableEmails.length === 1) {
        return availableEmails[0].email;
    }
    return undefined;
};
exports.getLastEmail = getLastEmail;
//# sourceMappingURL=getLastEmail.js.map