"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecentItemsManager = exports.GetRecentItemsHeaders = void 0;
const recentItems_1 = require("../schemas/recentItems");
const network_1 = require("../networking/network");
const fetchOptions_1 = require("../networking/fetchOptions");
const utils_1 = require("../internal/utils");
const utils_2 = require("../internal/utils");
class GetRecentItemsHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetRecentItemsHeaders = GetRecentItemsHeaders;
class RecentItemsManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
     * Returns information about the recent items accessed
     * by a user, either in the last 90 days or up to the last
     * 1000 items accessed.
     * @param {GetRecentItemsQueryParams} queryParams Query parameters of getRecentItems method
     * @param {GetRecentItemsHeadersInput} headersInput Headers of getRecentItems method
     * @param {CancellationToken} cancellationToken Token used for request cancellation.
     * @returns {Promise<RecentItems>}
     */
    async getRecentItems(queryParams = {}, headersInput = new GetRecentItemsHeaders({}), cancellationToken) {
        const headers = new GetRecentItemsHeaders({
            extraHeaders: headersInput.extraHeaders,
        });
        const queryParamsMap = (0, utils_1.prepareParams)({
            ['fields']: queryParams.fields
                ? queryParams.fields.map(utils_2.toString).join(',')
                : undefined,
            ['limit']: (0, utils_2.toString)(queryParams.limit),
            ['marker']: (0, utils_2.toString)(queryParams.marker),
        });
        const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/recent_items'),
            method: 'GET',
            params: queryParamsMap,
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, recentItems_1.deserializeRecentItems)(response.data),
            rawData: response.data,
        };
    }
}
exports.RecentItemsManager = RecentItemsManager;
//# sourceMappingURL=recentItems.js.map