"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.elationMobilePhoneToE164 = void 0;
const libphonenumber_js_1 = require("libphonenumber-js");
const lodash_1 = require("lodash");
/**
 * Elation is a US-only EHR and they store mobile numbers without country code.
 * We can only work with mobile phones (e.g. to send an SMS) if the phone number is
 * in international (E.164) format so will have to parse the phone number.
 *
 * If we can't parse the phone number to international format, we'll set the
 * mobile phone to undefined.
 */
const elationMobilePhoneToE164 = (phoneNumber) => {
    if ((0, lodash_1.isNil)(phoneNumber))
        return undefined;
    const parsedNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(phoneNumber, 'US');
    if ((0, lodash_1.isNil)(parsedNumber) || !parsedNumber.isValid()) {
        return undefined;
    }
    return parsedNumber.format('E.164');
};
exports.elationMobilePhoneToE164 = elationMobilePhoneToE164;
//# sourceMappingURL=elationMobilePhoneToE164.js.map