"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.requestsCore = exports.requests = 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");
/**
 * The first time an address wants to send a message to another peer, the address sends an intent request. This first message shall not land in this peer Inbox but in its Request box.
 * This function will return all the chats that landed on the address' Request box. The user can then approve the request or ignore it for now.
 */
const requests = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    return yield (0, exports.requestsCore)(options, helpers_2.PGPHelper);
});
exports.requests = requests;
const requestsCore = (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 || {};
    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}/requests?page=${page}&limit=${limit}`;
    try {
        if (!(0, helpers_1.isValidETHAddress)(user)) {
            throw new Error(`Invalid address!`);
        }
        const response = yield axios_1.default.get(apiEndpoint);
        const requests = response.data.requests;
        const updatedRequests = (0, helpers_2.addDeprecatedInfo)(requests);
        const Feeds = yield (0, helpers_2.getInboxLists)({
            lists: updatedRequests,
            user,
            toDecrypt,
            pgpPrivateKey,
            env,
        }, pgpHelper);
        return Feeds;
    }
    catch (err) {
        console.error(`[Push SDK] - API ${exports.requests.name}: `, err);
        throw Error(`[Push SDK] - API ${exports.requests.name}: ${err}`);
    }
});
exports.requestsCore = requestsCore;
//# sourceMappingURL=requests.js.map