"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FolderClassificationsManager = exports.DeleteClassificationFromFolderHeaders = exports.UpdateClassificationOnFolderHeaders = exports.UpdateClassificationOnFolderRequestBody = exports.AddClassificationToFolderHeaders = exports.GetClassificationOnFolderHeaders = exports.DeleteClassificationFromFolderOptionals = exports.UpdateClassificationOnFolderOptionals = exports.AddClassificationToFolderOptionals = exports.GetClassificationOnFolderOptionals = void 0;
exports.serializeAddClassificationToFolderRequestBody = serializeAddClassificationToFolderRequestBody;
exports.deserializeAddClassificationToFolderRequestBody = deserializeAddClassificationToFolderRequestBody;
exports.serializeUpdateClassificationOnFolderRequestBodyOpField = serializeUpdateClassificationOnFolderRequestBodyOpField;
exports.deserializeUpdateClassificationOnFolderRequestBodyOpField = deserializeUpdateClassificationOnFolderRequestBodyOpField;
exports.serializeUpdateClassificationOnFolderRequestBodyPathField = serializeUpdateClassificationOnFolderRequestBodyPathField;
exports.deserializeUpdateClassificationOnFolderRequestBodyPathField = deserializeUpdateClassificationOnFolderRequestBodyPathField;
exports.serializeUpdateClassificationOnFolderRequestBody = serializeUpdateClassificationOnFolderRequestBody;
exports.deserializeUpdateClassificationOnFolderRequestBody = deserializeUpdateClassificationOnFolderRequestBody;
exports.serializeUpdateClassificationOnFolderRequestBodyInput = serializeUpdateClassificationOnFolderRequestBodyInput;
exports.deserializeUpdateClassificationOnFolderRequestBodyInput = deserializeUpdateClassificationOnFolderRequestBodyInput;
const classification_1 = require("../schemas/classification");
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 GetClassificationOnFolderOptionals {
    headers = new GetClassificationOnFolderHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetClassificationOnFolderOptionals = GetClassificationOnFolderOptionals;
class AddClassificationToFolderOptionals {
    requestBody = {};
    headers = new AddClassificationToFolderHeaders({});
    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.AddClassificationToFolderOptionals = AddClassificationToFolderOptionals;
class UpdateClassificationOnFolderOptionals {
    headers = new UpdateClassificationOnFolderHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.UpdateClassificationOnFolderOptionals = UpdateClassificationOnFolderOptionals;
class DeleteClassificationFromFolderOptionals {
    headers = new DeleteClassificationFromFolderHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteClassificationFromFolderOptionals = DeleteClassificationFromFolderOptionals;
class GetClassificationOnFolderHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetClassificationOnFolderHeaders = GetClassificationOnFolderHeaders;
class AddClassificationToFolderHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.AddClassificationToFolderHeaders = AddClassificationToFolderHeaders;
class UpdateClassificationOnFolderRequestBody {
    /**
     * The value will always be `replace`. */
    op = 'replace';
    /**
     * Defines classifications
     * available in the enterprise. */
    path = '/Box__Security__Classification__Key';
    /**
     * The name of the classification to apply to this folder.
     *
     * To list the available classifications in an enterprise,
     * use the classification API to retrieve the
     * [classification template](https://developer.box.com/reference/get-metadata-templates-enterprise-securityClassification-6VMVochwUWo-schema)
     * which lists all available classification keys. */
    value;
    rawData;
    constructor(fields) {
        if (fields.op !== undefined) {
            this.op = fields.op;
        }
        if (fields.path !== undefined) {
            this.path = fields.path;
        }
        if (fields.value !== undefined) {
            this.value = fields.value;
        }
        if (fields.rawData !== undefined) {
            this.rawData = fields.rawData;
        }
    }
}
exports.UpdateClassificationOnFolderRequestBody = UpdateClassificationOnFolderRequestBody;
class UpdateClassificationOnFolderHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.UpdateClassificationOnFolderHeaders = UpdateClassificationOnFolderHeaders;
class DeleteClassificationFromFolderHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteClassificationFromFolderHeaders = DeleteClassificationFromFolderHeaders;
class FolderClassificationsManager {
    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 classification metadata instance that
       * has been applied to a folder.
       *
       * This API can also be called by including the enterprise ID in the
       * URL explicitly, for example
       * `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`.
       * @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 {GetClassificationOnFolderOptionalsInput} optionalsInput
       * @returns {Promise<Classification>}
       */
    async getClassificationOnFolder(folderId, optionalsInput = {}) {
        const optionals = new GetClassificationOnFolderOptionals({
            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), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, classification_1.deserializeClassification)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Adds a classification to a folder by specifying the label of the
       * classification to add.
       *
       * This API can also be called by including the enterprise ID in the
       * URL explicitly, for example
       * `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`.
       * @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 {AddClassificationToFolderOptionalsInput} optionalsInput
       * @returns {Promise<Classification>}
       */
    async addClassificationToFolder(folderId, optionalsInput = {}) {
        const optionals = new AddClassificationToFolderOptionals({
            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_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), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'POST',
            headers: headersMap,
            data: serializeAddClassificationToFolderRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, classification_1.deserializeClassification)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Updates a classification on a folder.
       *
       * The classification can only be updated if a classification has already been
       * applied to the folder before. When editing classifications, only values are
       * defined for the enterprise will be accepted.
       * @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 {readonly UpdateClassificationOnFolderRequestBody[]} requestBody Request body of updateClassificationOnFolder method
       * @param {UpdateClassificationOnFolderOptionalsInput} optionalsInput
       * @returns {Promise<Classification>}
       */
    async updateClassificationOnFolder(folderId, requestBody, optionalsInput = {}) {
        const optionals = new UpdateClassificationOnFolderOptionals({
            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), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'PUT',
            headers: headersMap,
            data: requestBody.map(serializeUpdateClassificationOnFolderRequestBody),
            contentType: 'application/json-patch+json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, classification_1.deserializeClassification)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Removes any classifications from a folder.
       *
       * This API can also be called by including the enterprise ID in the
       * URL explicitly, for example
       * `/folders/:id/enterprise_12345/securityClassification-6VMVochwUWo`.
       * @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 {DeleteClassificationFromFolderOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteClassificationFromFolder(folderId, optionalsInput = {}) {
        const optionals = new DeleteClassificationFromFolderOptionals({
            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), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
}
exports.FolderClassificationsManager = FolderClassificationsManager;
function serializeAddClassificationToFolderRequestBody(val) {
    return {
        ['Box__Security__Classification__Key']: val.boxSecurityClassificationKey,
    };
}
function deserializeAddClassificationToFolderRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "AddClassificationToFolderRequestBody"',
        });
    }
    if (!(val.Box__Security__Classification__Key == void 0) &&
        !(0, json_1.sdIsString)(val.Box__Security__Classification__Key)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "Box__Security__Classification__Key" of type "AddClassificationToFolderRequestBody"',
        });
    }
    const boxSecurityClassificationKey = val.Box__Security__Classification__Key == void 0
        ? void 0
        : val.Box__Security__Classification__Key;
    return {
        boxSecurityClassificationKey: boxSecurityClassificationKey,
    };
}
function serializeUpdateClassificationOnFolderRequestBodyOpField(val) {
    return val;
}
function deserializeUpdateClassificationOnFolderRequestBodyOpField(val) {
    if (val == 'replace') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize UpdateClassificationOnFolderRequestBodyOpField",
    });
}
function serializeUpdateClassificationOnFolderRequestBodyPathField(val) {
    return val;
}
function deserializeUpdateClassificationOnFolderRequestBodyPathField(val) {
    if (val == '/Box__Security__Classification__Key') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize UpdateClassificationOnFolderRequestBodyPathField",
    });
}
function serializeUpdateClassificationOnFolderRequestBody(val) {
    return {
        ['op']: serializeUpdateClassificationOnFolderRequestBodyOpField(val.op),
        ['path']: serializeUpdateClassificationOnFolderRequestBodyPathField(val.path),
        ['value']: val.value,
    };
}
function deserializeUpdateClassificationOnFolderRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateClassificationOnFolderRequestBody"',
        });
    }
    if (val.op == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "op" of type "UpdateClassificationOnFolderRequestBody" to be defined',
        });
    }
    const op = deserializeUpdateClassificationOnFolderRequestBodyOpField(val.op);
    if (val.path == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "path" of type "UpdateClassificationOnFolderRequestBody" to be defined',
        });
    }
    const path = deserializeUpdateClassificationOnFolderRequestBodyPathField(val.path);
    if (val.value == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "value" of type "UpdateClassificationOnFolderRequestBody" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.value)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "value" of type "UpdateClassificationOnFolderRequestBody"',
        });
    }
    const value = val.value;
    return {
        op: op,
        path: path,
        value: value,
    };
}
function serializeUpdateClassificationOnFolderRequestBodyInput(val) {
    return {
        ['op']: val.op == void 0
            ? val.op
            : serializeUpdateClassificationOnFolderRequestBodyOpField(val.op),
        ['path']: val.path == void 0
            ? val.path
            : serializeUpdateClassificationOnFolderRequestBodyPathField(val.path),
        ['value']: val.value,
    };
}
function deserializeUpdateClassificationOnFolderRequestBodyInput(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateClassificationOnFolderRequestBodyInput"',
        });
    }
    const op = val.op == void 0
        ? void 0
        : deserializeUpdateClassificationOnFolderRequestBodyOpField(val.op);
    const path = val.path == void 0
        ? void 0
        : deserializeUpdateClassificationOnFolderRequestBodyPathField(val.path);
    if (val.value == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "value" of type "UpdateClassificationOnFolderRequestBodyInput" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.value)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "value" of type "UpdateClassificationOnFolderRequestBodyInput"',
        });
    }
    const value = val.value;
    return {
        op: op,
        path: path,
        value: value,
    };
}
//# sourceMappingURL=folderClassifications.js.map