"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.chatsCore = exports.chats = 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");
/**
 * Return the latest message from all wallet addresses you have talked to. This can be used when building the inbox page.
 */
const chats = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    return yield (0, exports.chatsCore)(options, helpers_2.PGPHelper);
});
exports.chats = chats;
const chatsCore = (options, pgpHelper) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    const { account, pgpPrivateKey, env = constants_1.default.ENV.PROD, toDecrypt = false, page = 1, limit = 10, } = options || {};
    if (!(0, helpers_1.isValidETHAddress)(account)) {
        throw new Error(`Invalid address!`);
    }
    const user = yield (0, helpers_2.getUserDID)(account, env);
    const API_BASE_URL = (0, helpers_1.getAPIBaseUrls)(env);
    const apiEndpoint = `${API_BASE_URL}/v1/chat/users/${user}/chats?page=${page}&limit=${limit}`;
    const requestUrl = `${apiEndpoint}`;
    try {
        const response = yield axios_1.default.get(requestUrl);
        const chats = response.data.chats;
        const updatedChats = (0, helpers_2.addDeprecatedInfo)(chats);
        const feeds = yield (0, helpers_2.getInboxLists)({
            lists: updatedChats,
            user: user,
            toDecrypt,
            pgpPrivateKey,
            env,
        }, pgpHelper);
        return feeds;
    }
    catch (err) {
        console.error(`[Push SDK] - API ${exports.chats.name}: `, err);
        throw Error(`[Push SDK] - API ${exports.chats.name}: ${err}`);
    }
});
exports.chatsCore = chatsCore;
//# sourceMappingURL=chats.js.map