"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileRequestsManager = exports.CreateFileRequestCopyHeaders = exports.DeleteFileRequestByIdHeaders = exports.UpdateFileRequestByIdHeaders = exports.GetFileRequestByIdHeaders = exports.CreateFileRequestCopyOptionals = exports.DeleteFileRequestByIdOptionals = exports.UpdateFileRequestByIdOptionals = exports.GetFileRequestByIdOptionals = void 0;
const fileRequest_1 = require("../schemas/fileRequest");
const fileRequestUpdateRequest_1 = require("../schemas/fileRequestUpdateRequest");
const fileRequestCopyRequest_1 = require("../schemas/fileRequestCopyRequest");
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 GetFileRequestByIdOptionals {
    headers = new GetFileRequestByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetFileRequestByIdOptionals = GetFileRequestByIdOptionals;
class UpdateFileRequestByIdOptionals {
    headers = new UpdateFileRequestByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.UpdateFileRequestByIdOptionals = UpdateFileRequestByIdOptionals;
class DeleteFileRequestByIdOptionals {
    headers = new DeleteFileRequestByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteFileRequestByIdOptionals = DeleteFileRequestByIdOptionals;
class CreateFileRequestCopyOptionals {
    headers = new CreateFileRequestCopyHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.CreateFileRequestCopyOptionals = CreateFileRequestCopyOptionals;
class GetFileRequestByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetFileRequestByIdHeaders = GetFileRequestByIdHeaders;
class UpdateFileRequestByIdHeaders {
    /**
     * Ensures this item hasn't recently changed before
     * making changes.
     *
     * Pass in the item's last observed `etag` value
     * into this header and the endpoint will fail
     * with a `412 Precondition Failed` if it
     * has changed since. */
    ifMatch;
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.ifMatch !== undefined) {
            this.ifMatch = fields.ifMatch;
        }
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.UpdateFileRequestByIdHeaders = UpdateFileRequestByIdHeaders;
class DeleteFileRequestByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteFileRequestByIdHeaders = DeleteFileRequestByIdHeaders;
class CreateFileRequestCopyHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.CreateFileRequestCopyHeaders = CreateFileRequestCopyHeaders;
class FileRequestsManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
       * Retrieves the information about a file request.
       * @param {string} fileRequestId The unique identifier that represent a file request.
      
      The ID for any file request can be determined
      by visiting a file request builder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/filerequest/123`
      the `file_request_id` is `123`.
      Example: "123"
       * @param {GetFileRequestByIdOptionalsInput} optionalsInput
       * @returns {Promise<FileRequest>}
       */
    async getFileRequestById(fileRequestId, optionalsInput = {}) {
        const optionals = new GetFileRequestByIdOptionals({
            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/file_requests/', (0, utils_2.toString)(fileRequestId)),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, fileRequest_1.deserializeFileRequest)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Updates a file request. This can be used to activate or
       * deactivate a file request.
       * @param {string} fileRequestId The unique identifier that represent a file request.
      
      The ID for any file request can be determined
      by visiting a file request builder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/filerequest/123`
      the `file_request_id` is `123`.
      Example: "123"
       * @param {FileRequestUpdateRequest} requestBody Request body of updateFileRequestById method
       * @param {UpdateFileRequestByIdOptionalsInput} optionalsInput
       * @returns {Promise<FileRequest>}
       */
    async updateFileRequestById(fileRequestId, requestBody, optionalsInput = {}) {
        const optionals = new UpdateFileRequestByIdOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({
            ...{ ['if-match']: (0, utils_2.toString)(headers.ifMatch) },
            ...headers.extraHeaders,
        });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/file_requests/', (0, utils_2.toString)(fileRequestId)),
            method: 'PUT',
            headers: headersMap,
            data: (0, fileRequestUpdateRequest_1.serializeFileRequestUpdateRequest)(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, fileRequest_1.deserializeFileRequest)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Deletes a file request permanently.
       * @param {string} fileRequestId The unique identifier that represent a file request.
      
      The ID for any file request can be determined
      by visiting a file request builder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/filerequest/123`
      the `file_request_id` is `123`.
      Example: "123"
       * @param {DeleteFileRequestByIdOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteFileRequestById(fileRequestId, optionalsInput = {}) {
        const optionals = new DeleteFileRequestByIdOptionals({
            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/file_requests/', (0, utils_2.toString)(fileRequestId)),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
    /**
       * Copies an existing file request that is already present on one folder,
       * and applies it to another folder.
       * @param {string} fileRequestId The unique identifier that represent a file request.
      
      The ID for any file request can be determined
      by visiting a file request builder in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/filerequest/123`
      the `file_request_id` is `123`.
      Example: "123"
       * @param {FileRequestCopyRequest} requestBody Request body of createFileRequestCopy method
       * @param {CreateFileRequestCopyOptionalsInput} optionalsInput
       * @returns {Promise<FileRequest>}
       */
    async createFileRequestCopy(fileRequestId, requestBody, optionalsInput = {}) {
        const optionals = new CreateFileRequestCopyOptionals({
            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/file_requests/', (0, utils_2.toString)(fileRequestId), '/copy'),
            method: 'POST',
            headers: headersMap,
            data: (0, fileRequestCopyRequest_1.serializeFileRequestCopyRequest)(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, fileRequest_1.deserializeFileRequest)(response.data),
            rawData: response.data,
        };
    }
}
exports.FileRequestsManager = FileRequestsManager;
//# sourceMappingURL=fileRequests.js.map