"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebLinksManager = exports.DeleteWebLinkByIdHeaders = exports.UpdateWebLinkByIdHeaders = exports.GetWebLinkByIdHeaders = exports.CreateWebLinkHeaders = exports.DeleteWebLinkByIdOptionals = exports.UpdateWebLinkByIdOptionals = exports.GetWebLinkByIdOptionals = exports.CreateWebLinkOptionals = void 0;
exports.serializeCreateWebLinkRequestBodyParentField = serializeCreateWebLinkRequestBodyParentField;
exports.deserializeCreateWebLinkRequestBodyParentField = deserializeCreateWebLinkRequestBodyParentField;
exports.serializeCreateWebLinkRequestBody = serializeCreateWebLinkRequestBody;
exports.deserializeCreateWebLinkRequestBody = deserializeCreateWebLinkRequestBody;
exports.serializeUpdateWebLinkByIdRequestBodyParentField = serializeUpdateWebLinkByIdRequestBodyParentField;
exports.deserializeUpdateWebLinkByIdRequestBodyParentField = deserializeUpdateWebLinkByIdRequestBodyParentField;
exports.serializeUpdateWebLinkByIdRequestBodySharedLinkAccessField = serializeUpdateWebLinkByIdRequestBodySharedLinkAccessField;
exports.deserializeUpdateWebLinkByIdRequestBodySharedLinkAccessField = deserializeUpdateWebLinkByIdRequestBodySharedLinkAccessField;
exports.serializeUpdateWebLinkByIdRequestBodySharedLinkField = serializeUpdateWebLinkByIdRequestBodySharedLinkField;
exports.deserializeUpdateWebLinkByIdRequestBodySharedLinkField = deserializeUpdateWebLinkByIdRequestBodySharedLinkField;
exports.serializeUpdateWebLinkByIdRequestBody = serializeUpdateWebLinkByIdRequestBody;
exports.deserializeUpdateWebLinkByIdRequestBody = deserializeUpdateWebLinkByIdRequestBody;
const webLink_1 = require("../schemas/webLink");
const utils_1 = require("../internal/utils");
const utils_2 = require("../internal/utils");
const errors_1 = require("../box/errors");
const network_1 = require("../networking/network");
const fetchOptions_1 = require("../networking/fetchOptions");
const utils_3 = require("../internal/utils");
const utils_4 = require("../internal/utils");
const json_1 = require("../serialization/json");
const json_2 = require("../serialization/json");
class CreateWebLinkOptionals {
    headers = new CreateWebLinkHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.CreateWebLinkOptionals = CreateWebLinkOptionals;
class GetWebLinkByIdOptionals {
    headers = new GetWebLinkByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetWebLinkByIdOptionals = GetWebLinkByIdOptionals;
class UpdateWebLinkByIdOptionals {
    requestBody = {};
    headers = new UpdateWebLinkByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.requestBody !== undefined) {
            this.requestBody = fields.requestBody;
        }
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.UpdateWebLinkByIdOptionals = UpdateWebLinkByIdOptionals;
class DeleteWebLinkByIdOptionals {
    headers = new DeleteWebLinkByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteWebLinkByIdOptionals = DeleteWebLinkByIdOptionals;
class CreateWebLinkHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.CreateWebLinkHeaders = CreateWebLinkHeaders;
class GetWebLinkByIdHeaders {
    /**
     * The URL, and optional password, for the shared link of this item.
     *
     * This header can be used to access items that have not been
     * explicitly shared with a user.
     *
     * Use the format `shared_link=[link]` or if a password is required then
     * use `shared_link=[link]&shared_link_password=[password]`.
     *
     * This header can be used on the file or folder shared, as well as on any files
     * or folders nested within the item. */
    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.GetWebLinkByIdHeaders = GetWebLinkByIdHeaders;
class UpdateWebLinkByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.UpdateWebLinkByIdHeaders = UpdateWebLinkByIdHeaders;
class DeleteWebLinkByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteWebLinkByIdHeaders = DeleteWebLinkByIdHeaders;
class WebLinksManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
     * Creates a web link object within a folder.
     * @param {CreateWebLinkRequestBody} requestBody Request body of createWebLink method
     * @param {CreateWebLinkOptionalsInput} optionalsInput
     * @returns {Promise<WebLink>}
     */
    async createWebLink(requestBody, optionalsInput = {}) {
        const optionals = new CreateWebLinkOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_3.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/web_links'),
            method: 'POST',
            headers: headersMap,
            data: serializeCreateWebLinkRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, webLink_1.deserializeWebLink)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Retrieve information about a web link.
       * @param {string} webLinkId The ID of the web link.
      Example: "12345"
       * @param {GetWebLinkByIdOptionalsInput} optionalsInput
       * @returns {Promise<WebLink>}
       */
    async getWebLinkById(webLinkId, optionalsInput = {}) {
        const optionals = new GetWebLinkByIdOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_3.prepareParams)({
            ...{ ['boxapi']: (0, utils_4.toString)(headers.boxapi) },
            ...headers.extraHeaders,
        });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/web_links/', (0, utils_4.toString)(webLinkId)),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, webLink_1.deserializeWebLink)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Updates a web link object.
       * @param {string} webLinkId The ID of the web link.
      Example: "12345"
       * @param {UpdateWebLinkByIdOptionalsInput} optionalsInput
       * @returns {Promise<WebLink>}
       */
    async updateWebLinkById(webLinkId, optionalsInput = {}) {
        const optionals = new UpdateWebLinkByIdOptionals({
            requestBody: optionalsInput.requestBody,
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const requestBody = optionals.requestBody;
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_3.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/web_links/', (0, utils_4.toString)(webLinkId)),
            method: 'PUT',
            headers: headersMap,
            data: serializeUpdateWebLinkByIdRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, webLink_1.deserializeWebLink)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Deletes a web link.
       * @param {string} webLinkId The ID of the web link.
      Example: "12345"
       * @param {DeleteWebLinkByIdOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteWebLinkById(webLinkId, optionalsInput = {}) {
        const optionals = new DeleteWebLinkByIdOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_3.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/web_links/', (0, utils_4.toString)(webLinkId)),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
}
exports.WebLinksManager = WebLinksManager;
function serializeCreateWebLinkRequestBodyParentField(val) {
    return { ['id']: val.id };
}
function deserializeCreateWebLinkRequestBodyParentField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "CreateWebLinkRequestBodyParentField"',
        });
    }
    if (val.id == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "id" of type "CreateWebLinkRequestBodyParentField" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "id" of type "CreateWebLinkRequestBodyParentField"',
        });
    }
    const id = val.id;
    return { id: id };
}
function serializeCreateWebLinkRequestBody(val) {
    return {
        ['url']: val.url,
        ['parent']: serializeCreateWebLinkRequestBodyParentField(val.parent),
        ['name']: val.name,
        ['description']: val.description,
    };
}
function deserializeCreateWebLinkRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "CreateWebLinkRequestBody"',
        });
    }
    if (val.url == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "url" of type "CreateWebLinkRequestBody" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.url)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "url" of type "CreateWebLinkRequestBody"',
        });
    }
    const url = val.url;
    if (val.parent == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "parent" of type "CreateWebLinkRequestBody" to be defined',
        });
    }
    const parent = deserializeCreateWebLinkRequestBodyParentField(val.parent);
    if (!(val.name == void 0) && !(0, json_1.sdIsString)(val.name)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "name" of type "CreateWebLinkRequestBody"',
        });
    }
    const name = val.name == void 0 ? void 0 : val.name;
    if (!(val.description == void 0) && !(0, json_1.sdIsString)(val.description)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "description" of type "CreateWebLinkRequestBody"',
        });
    }
    const description = val.description == void 0 ? void 0 : val.description;
    return {
        url: url,
        parent: parent,
        name: name,
        description: description,
    };
}
function serializeUpdateWebLinkByIdRequestBodyParentField(val) {
    return { ['id']: val.id, ['user_id']: val.userId };
}
function deserializeUpdateWebLinkByIdRequestBodyParentField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateWebLinkByIdRequestBodyParentField"',
        });
    }
    if (!(val.id == void 0) && !(0, json_1.sdIsString)(val.id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "id" of type "UpdateWebLinkByIdRequestBodyParentField"',
        });
    }
    const id = val.id == void 0 ? void 0 : val.id;
    if (!(val.user_id == void 0) && !(0, json_1.sdIsString)(val.user_id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "user_id" of type "UpdateWebLinkByIdRequestBodyParentField"',
        });
    }
    const userId = val.user_id == void 0 ? void 0 : val.user_id;
    return {
        id: id,
        userId: userId,
    };
}
function serializeUpdateWebLinkByIdRequestBodySharedLinkAccessField(val) {
    return val;
}
function deserializeUpdateWebLinkByIdRequestBodySharedLinkAccessField(val) {
    if (val == 'open') {
        return val;
    }
    if (val == 'company') {
        return val;
    }
    if (val == 'collaborators') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize UpdateWebLinkByIdRequestBodySharedLinkAccessField",
    });
}
function serializeUpdateWebLinkByIdRequestBodySharedLinkField(val) {
    return {
        ['access']: val.access == void 0
            ? val.access
            : serializeUpdateWebLinkByIdRequestBodySharedLinkAccessField(val.access),
        ['password']: val.password,
        ['vanity_name']: val.vanityName,
        ['unshared_at']: val.unsharedAt == void 0
            ? val.unsharedAt
            : (0, utils_1.serializeDateTime)(val.unsharedAt),
    };
}
function deserializeUpdateWebLinkByIdRequestBodySharedLinkField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateWebLinkByIdRequestBodySharedLinkField"',
        });
    }
    const access = val.access == void 0
        ? void 0
        : deserializeUpdateWebLinkByIdRequestBodySharedLinkAccessField(val.access);
    if (!(val.password == void 0) && !(0, json_1.sdIsString)(val.password)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "password" of type "UpdateWebLinkByIdRequestBodySharedLinkField"',
        });
    }
    const password = val.password == void 0 ? void 0 : val.password;
    if (!(val.vanity_name == void 0) && !(0, json_1.sdIsString)(val.vanity_name)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "vanity_name" of type "UpdateWebLinkByIdRequestBodySharedLinkField"',
        });
    }
    const vanityName = val.vanity_name == void 0 ? void 0 : val.vanity_name;
    if (!(val.unshared_at == void 0) && !(0, json_1.sdIsString)(val.unshared_at)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "unshared_at" of type "UpdateWebLinkByIdRequestBodySharedLinkField"',
        });
    }
    const unsharedAt = val.unshared_at == void 0 ? void 0 : (0, utils_2.deserializeDateTime)(val.unshared_at);
    return {
        access: access,
        password: password,
        vanityName: vanityName,
        unsharedAt: unsharedAt,
    };
}
function serializeUpdateWebLinkByIdRequestBody(val) {
    return {
        ['url']: val.url,
        ['parent']: val.parent == void 0
            ? val.parent
            : serializeUpdateWebLinkByIdRequestBodyParentField(val.parent),
        ['name']: val.name,
        ['description']: val.description,
        ['shared_link']: val.sharedLink == void 0
            ? val.sharedLink
            : serializeUpdateWebLinkByIdRequestBodySharedLinkField(val.sharedLink),
    };
}
function deserializeUpdateWebLinkByIdRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateWebLinkByIdRequestBody"',
        });
    }
    if (!(val.url == void 0) && !(0, json_1.sdIsString)(val.url)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "url" of type "UpdateWebLinkByIdRequestBody"',
        });
    }
    const url = val.url == void 0 ? void 0 : val.url;
    const parent = val.parent == void 0
        ? void 0
        : deserializeUpdateWebLinkByIdRequestBodyParentField(val.parent);
    if (!(val.name == void 0) && !(0, json_1.sdIsString)(val.name)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "name" of type "UpdateWebLinkByIdRequestBody"',
        });
    }
    const name = val.name == void 0 ? void 0 : val.name;
    if (!(val.description == void 0) && !(0, json_1.sdIsString)(val.description)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "description" of type "UpdateWebLinkByIdRequestBody"',
        });
    }
    const description = val.description == void 0 ? void 0 : val.description;
    const sharedLink = val.shared_link == void 0
        ? void 0
        : deserializeUpdateWebLinkByIdRequestBodySharedLinkField(val.shared_link);
    return {
        url: url,
        parent: parent,
        name: name,
        description: description,
        sharedLink: sharedLink,
    };
}
//# sourceMappingURL=webLinks.js.map