"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrashedFoldersManager = exports.DeleteTrashedFolderByIdHeaders = exports.GetTrashedFolderByIdHeaders = exports.RestoreFolderFromTrashHeaders = exports.DeleteTrashedFolderByIdOptionals = exports.GetTrashedFolderByIdOptionals = exports.RestoreFolderFromTrashOptionals = void 0;
exports.serializeRestoreFolderFromTrashRequestBodyParentField = serializeRestoreFolderFromTrashRequestBodyParentField;
exports.deserializeRestoreFolderFromTrashRequestBodyParentField = deserializeRestoreFolderFromTrashRequestBodyParentField;
exports.serializeRestoreFolderFromTrashRequestBody = serializeRestoreFolderFromTrashRequestBody;
exports.deserializeRestoreFolderFromTrashRequestBody = deserializeRestoreFolderFromTrashRequestBody;
const trashFolderRestored_1 = require("../schemas/trashFolderRestored");
const trashFolder_1 = require("../schemas/trashFolder");
const errors_1 = require("../box/errors");
const network_1 = require("../networking/network");
const fetchOptions_1 = require("../networking/fetchOptions");
const utils_1 = require("../internal/utils");
const utils_2 = require("../internal/utils");
const json_1 = require("../serialization/json");
const json_2 = require("../serialization/json");
class RestoreFolderFromTrashOptionals {
    requestBody = {};
    queryParams = {};
    headers = new RestoreFolderFromTrashHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.requestBody !== undefined) {
            this.requestBody = fields.requestBody;
        }
        if (fields.queryParams !== undefined) {
            this.queryParams = fields.queryParams;
        }
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.RestoreFolderFromTrashOptionals = RestoreFolderFromTrashOptionals;
class GetTrashedFolderByIdOptionals {
    queryParams = {};
    headers = new GetTrashedFolderByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.queryParams !== undefined) {
            this.queryParams = fields.queryParams;
        }
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetTrashedFolderByIdOptionals = GetTrashedFolderByIdOptionals;
class DeleteTrashedFolderByIdOptionals {
    headers = new DeleteTrashedFolderByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteTrashedFolderByIdOptionals = DeleteTrashedFolderByIdOptionals;
class RestoreFolderFromTrashHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.RestoreFolderFromTrashHeaders = RestoreFolderFromTrashHeaders;
class GetTrashedFolderByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetTrashedFolderByIdHeaders = GetTrashedFolderByIdHeaders;
class DeleteTrashedFolderByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteTrashedFolderByIdHeaders = DeleteTrashedFolderByIdHeaders;
class TrashedFoldersManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
       * Restores a folder that has been moved to the trash.
       *
       * An optional new parent ID can be provided to restore the folder to in case the
       * original folder has been deleted.
       *
       * During this operation, part of the file tree will be locked, mainly
       * the source folder and all of its descendants, as well as the destination
       * folder.
       *
       * For the duration of the operation, no other move, copy, delete, or restore
       * operation can performed on any of the locked folders.
       * @param {string} folderId The unique identifier that represent a folder.
      
      The ID for any folder can be determined
      by visiting this folder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/folder/123`
      the `folder_id` is `123`.
      
      The root folder of a Box account is
      always represented by the ID `0`.
      Example: "12345"
       * @param {RestoreFolderFromTrashOptionalsInput} optionalsInput
       * @returns {Promise<TrashFolderRestored>}
       */
    async restoreFolderFromTrash(folderId, optionalsInput = {}) {
        const optionals = new RestoreFolderFromTrashOptionals({
            requestBody: optionalsInput.requestBody,
            queryParams: optionalsInput.queryParams,
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const requestBody = optionals.requestBody;
        const queryParams = optionals.queryParams;
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const queryParamsMap = (0, utils_1.prepareParams)({
            ['fields']: queryParams.fields
                ? queryParams.fields.map(utils_2.toString).join(',')
                : undefined,
        });
        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/folders/', (0, utils_2.toString)(folderId)),
            method: 'POST',
            params: queryParamsMap,
            headers: headersMap,
            data: serializeRestoreFolderFromTrashRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, trashFolderRestored_1.deserializeTrashFolderRestored)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Retrieves a folder that has been moved to the trash.
       *
       * Please note that only if the folder itself has been moved to the
       * trash can it be retrieved with this API call. If instead one of
       * its parent folders was moved to the trash, only that folder
       * can be inspected using the
       * [`GET /folders/:id/trash`](https://developer.box.com/reference/get-folders-id-trash) API.
       *
       * To list all items that have been moved to the trash, please
       * use the [`GET /folders/trash/items`](https://developer.box.com/reference/get-folders-trash-items/)
       * API.
       * @param {string} folderId The unique identifier that represent a folder.
      
      The ID for any folder can be determined
      by visiting this folder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/folder/123`
      the `folder_id` is `123`.
      
      The root folder of a Box account is
      always represented by the ID `0`.
      Example: "12345"
       * @param {GetTrashedFolderByIdOptionalsInput} optionalsInput
       * @returns {Promise<TrashFolder>}
       */
    async getTrashedFolderById(folderId, optionalsInput = {}) {
        const optionals = new GetTrashedFolderByIdOptionals({
            queryParams: optionalsInput.queryParams,
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const queryParams = optionals.queryParams;
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const queryParamsMap = (0, utils_1.prepareParams)({
            ['fields']: queryParams.fields
                ? queryParams.fields.map(utils_2.toString).join(',')
                : undefined,
        });
        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/folders/', (0, utils_2.toString)(folderId), '/trash'),
            method: 'GET',
            params: queryParamsMap,
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, trashFolder_1.deserializeTrashFolder)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Permanently deletes a folder that is in the trash.
       * This action cannot be undone.
       * @param {string} folderId The unique identifier that represent a folder.
      
      The ID for any folder can be determined
      by visiting this folder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/folder/123`
      the `folder_id` is `123`.
      
      The root folder of a Box account is
      always represented by the ID `0`.
      Example: "12345"
       * @param {DeleteTrashedFolderByIdOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteTrashedFolderById(folderId, optionalsInput = {}) {
        const optionals = new DeleteTrashedFolderByIdOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        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/folders/', (0, utils_2.toString)(folderId), '/trash'),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
}
exports.TrashedFoldersManager = TrashedFoldersManager;
function serializeRestoreFolderFromTrashRequestBodyParentField(val) {
    return { ['id']: val.id };
}
function deserializeRestoreFolderFromTrashRequestBodyParentField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "RestoreFolderFromTrashRequestBodyParentField"',
        });
    }
    if (!(val.id == void 0) && !(0, json_1.sdIsString)(val.id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "id" of type "RestoreFolderFromTrashRequestBodyParentField"',
        });
    }
    const id = val.id == void 0 ? void 0 : val.id;
    return { id: id };
}
function serializeRestoreFolderFromTrashRequestBody(val) {
    return {
        ['name']: val.name,
        ['parent']: val.parent == void 0
            ? val.parent
            : serializeRestoreFolderFromTrashRequestBodyParentField(val.parent),
    };
}
function deserializeRestoreFolderFromTrashRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "RestoreFolderFromTrashRequestBody"',
        });
    }
    if (!(val.name == void 0) && !(0, json_1.sdIsString)(val.name)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "name" of type "RestoreFolderFromTrashRequestBody"',
        });
    }
    const name = val.name == void 0 ? void 0 : val.name;
    const parent = val.parent == void 0
        ? void 0
        : deserializeRestoreFolderFromTrashRequestBodyParentField(val.parent);
    return {
        name: name,
        parent: parent,
    };
}
//# sourceMappingURL=trashedFolders.js.map