"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../utils");
function httpsCallable(functionName) {
    var functions = FIRFunctions.functions();
    return function (data) { return new Promise(function (resolve, reject) {
        var callable = functions.HTTPSCallableWithName(functionName);
        var handleCompletion = function (result, err) {
            if (err) {
                reject(err.localizedDescription);
                return;
            }
            if (result) {
                resolve(utils_1.firebaseUtils.toJsObject(result.data));
            }
        };
        if (data) {
            callable.callWithObjectCompletion(data, handleCompletion);
        }
        else {
            callable.callWithCompletion(handleCompletion);
        }
    }); };
}
exports.httpsCallable = httpsCallable;
