"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SharedLinksAppItemsManager = exports.FindAppItemForSharedLinkHeaders = exports.FindAppItemForSharedLinkOptionals = void 0;
const appItem_1 = require("../schemas/appItem");
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 FindAppItemForSharedLinkOptionals {
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.FindAppItemForSharedLinkOptionals = FindAppItemForSharedLinkOptionals;
class FindAppItemForSharedLinkHeaders {
    /**
     * A header containing the shared link and optional password for the
     * shared link.
     *
     * The format for this header is `shared_link=[link]&shared_link_password=[password]`. */
    boxapi;
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.boxapi !== undefined) {
            this.boxapi = fields.boxapi;
        }
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.FindAppItemForSharedLinkHeaders = FindAppItemForSharedLinkHeaders;
class SharedLinksAppItemsManager {
    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 the app item represented by a shared link.
     *
     * The link can originate from the current enterprise or another.
     * @param {FindAppItemForSharedLinkHeadersInput} headersInput Headers of findAppItemForSharedLink method
     * @param {FindAppItemForSharedLinkOptionalsInput} optionalsInput
     * @returns {Promise<AppItem>}
     */
    async findAppItemForSharedLink(headersInput, optionalsInput = {}) {
        const headers = new FindAppItemForSharedLinkHeaders({
            boxapi: headersInput.boxapi,
            extraHeaders: headersInput.extraHeaders,
        });
        const optionals = new FindAppItemForSharedLinkOptionals({
            cancellationToken: optionalsInput.cancellationToken,
        });
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({
            ...{ ['boxapi']: (0, utils_2.toString)(headers.boxapi) },
            ...headers.extraHeaders,
        });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/shared_items#app_items'),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, appItem_1.deserializeAppItem)(response.data),
            rawData: response.data,
        };
    }
}
exports.SharedLinksAppItemsManager = SharedLinksAppItemsManager;
//# sourceMappingURL=sharedLinksAppItems.js.map