"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.chat = void 0;
const tslib_1 = require("tslib");
const axios_1 = require("axios");
const helpers_1 = require("../helpers");
const constants_1 = require("../constants");
const helpers_2 = require("./helpers");
const chat = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    const { account, pgpPrivateKey, env = constants_1.default.ENV.PROD, toDecrypt = false, recipient, } = options || {};
    const user = yield (0, helpers_2.getUserDID)(account, env);
    const recipientWallet = yield (0, helpers_2.getUserDID)(recipient, env);
    if (!(0, helpers_1.isValidETHAddress)(user))
        throw new Error(`Invalid address ${user}`);
    const API_BASE_URL = (0, helpers_1.getAPIBaseUrls)(env);
    const apiEndpoint = `${API_BASE_URL}/v1/chat/users/${user}/chat/${recipientWallet}`;
    try {
        const response = yield axios_1.default.get(apiEndpoint);
        // If no chat between users, then returns {}
        const chat = response.data;
        if (Object.keys(chat).length !== 0) {
            const updatedChat = (0, helpers_2.addDeprecatedInfo)([chat]);
            const [feed] = yield (0, helpers_2.getInboxLists)({
                lists: updatedChat,
                user,
                toDecrypt,
                pgpPrivateKey,
                env,
            }, helpers_2.PGPHelper);
            return feed;
        }
        else {
            return chat;
        }
    }
    catch (err) {
        console.error(`[Push SDK] - API ${exports.chat.name}: `, err);
        throw Error(`[Push SDK] - API ${exports.chat.name}: ${err}`);
    }
});
exports.chat = chat;
//# sourceMappingURL=chat.js.map