"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileClassificationsManager = exports.DeleteClassificationFromFileHeaders = exports.UpdateClassificationOnFileHeaders = exports.UpdateClassificationOnFileRequestBody = exports.AddClassificationToFileHeaders = exports.GetClassificationOnFileHeaders = exports.DeleteClassificationFromFileOptionals = exports.UpdateClassificationOnFileOptionals = exports.AddClassificationToFileOptionals = exports.GetClassificationOnFileOptionals = void 0;
exports.serializeAddClassificationToFileRequestBody = serializeAddClassificationToFileRequestBody;
exports.deserializeAddClassificationToFileRequestBody = deserializeAddClassificationToFileRequestBody;
exports.serializeUpdateClassificationOnFileRequestBodyOpField = serializeUpdateClassificationOnFileRequestBodyOpField;
exports.deserializeUpdateClassificationOnFileRequestBodyOpField = deserializeUpdateClassificationOnFileRequestBodyOpField;
exports.serializeUpdateClassificationOnFileRequestBodyPathField = serializeUpdateClassificationOnFileRequestBodyPathField;
exports.deserializeUpdateClassificationOnFileRequestBodyPathField = deserializeUpdateClassificationOnFileRequestBodyPathField;
exports.serializeUpdateClassificationOnFileRequestBody = serializeUpdateClassificationOnFileRequestBody;
exports.deserializeUpdateClassificationOnFileRequestBody = deserializeUpdateClassificationOnFileRequestBody;
exports.serializeUpdateClassificationOnFileRequestBodyInput = serializeUpdateClassificationOnFileRequestBodyInput;
exports.deserializeUpdateClassificationOnFileRequestBodyInput = deserializeUpdateClassificationOnFileRequestBodyInput;
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 GetClassificationOnFileOptionals {
    headers = new GetClassificationOnFileHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetClassificationOnFileOptionals = GetClassificationOnFileOptionals;
class AddClassificationToFileOptionals {
    requestBody = {};
    headers = new AddClassificationToFileHeaders({});
    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.AddClassificationToFileOptionals = AddClassificationToFileOptionals;
class UpdateClassificationOnFileOptionals {
    headers = new UpdateClassificationOnFileHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.UpdateClassificationOnFileOptionals = UpdateClassificationOnFileOptionals;
class DeleteClassificationFromFileOptionals {
    headers = new DeleteClassificationFromFileHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteClassificationFromFileOptionals = DeleteClassificationFromFileOptionals;
class GetClassificationOnFileHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetClassificationOnFileHeaders = GetClassificationOnFileHeaders;
class AddClassificationToFileHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.AddClassificationToFileHeaders = AddClassificationToFileHeaders;
class UpdateClassificationOnFileRequestBody {
    /**
     * 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 file.
     *
     * 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.UpdateClassificationOnFileRequestBody = UpdateClassificationOnFileRequestBody;
class UpdateClassificationOnFileHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.UpdateClassificationOnFileHeaders = UpdateClassificationOnFileHeaders;
class DeleteClassificationFromFileHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteClassificationFromFileHeaders = DeleteClassificationFromFileHeaders;
class FileClassificationsManager {
    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 file.
       *
       * This API can also be called by including the enterprise ID in the
       * URL explicitly, for example
       * `/files/:id//enterprise_12345/securityClassification-6VMVochwUWo`.
       * @param {string} fileId The unique identifier that represents a file.
      
      The ID for any file can be determined
      by visiting a file in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/files/123`
      the `file_id` is `123`.
      Example: "12345"
       * @param {GetClassificationOnFileOptionalsInput} optionalsInput
       * @returns {Promise<Classification>}
       */
    async getClassificationOnFile(fileId, optionalsInput = {}) {
        const optionals = new GetClassificationOnFileOptionals({
            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/files/', (0, utils_2.toString)(fileId), '/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 file 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
       * `/files/:id//enterprise_12345/securityClassification-6VMVochwUWo`.
       * @param {string} fileId The unique identifier that represents a file.
      
      The ID for any file can be determined
      by visiting a file in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/files/123`
      the `file_id` is `123`.
      Example: "12345"
       * @param {AddClassificationToFileOptionalsInput} optionalsInput
       * @returns {Promise<Classification>}
       */
    async addClassificationToFile(fileId, optionalsInput = {}) {
        const optionals = new AddClassificationToFileOptionals({
            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/files/', (0, utils_2.toString)(fileId), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'POST',
            headers: headersMap,
            data: serializeAddClassificationToFileRequestBody(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 file.
       *
       * The classification can only be updated if a classification has already been
       * applied to the file before. When editing classifications, only values are
       * defined for the enterprise will be accepted.
       * @param {string} fileId The unique identifier that represents a file.
      
      The ID for any file can be determined
      by visiting a file in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/files/123`
      the `file_id` is `123`.
      Example: "12345"
       * @param {readonly UpdateClassificationOnFileRequestBody[]} requestBody Request body of updateClassificationOnFile method
       * @param {UpdateClassificationOnFileOptionalsInput} optionalsInput
       * @returns {Promise<Classification>}
       */
    async updateClassificationOnFile(fileId, requestBody, optionalsInput = {}) {
        const optionals = new UpdateClassificationOnFileOptionals({
            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/files/', (0, utils_2.toString)(fileId), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'PUT',
            headers: headersMap,
            data: requestBody.map(serializeUpdateClassificationOnFileRequestBody),
            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 file.
       *
       * This API can also be called by including the enterprise ID in the
       * URL explicitly, for example
       * `/files/:id//enterprise_12345/securityClassification-6VMVochwUWo`.
       * @param {string} fileId The unique identifier that represents a file.
      
      The ID for any file can be determined
      by visiting a file in the web application
      and copying the ID from the URL. For example,
      for the URL `https://*.app.box.com/files/123`
      the `file_id` is `123`.
      Example: "12345"
       * @param {DeleteClassificationFromFileOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteClassificationFromFile(fileId, optionalsInput = {}) {
        const optionals = new DeleteClassificationFromFileOptionals({
            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/files/', (0, utils_2.toString)(fileId), '/metadata/enterprise/securityClassification-6VMVochwUWo'),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
}
exports.FileClassificationsManager = FileClassificationsManager;
function serializeAddClassificationToFileRequestBody(val) {
    return {
        ['Box__Security__Classification__Key']: val.boxSecurityClassificationKey,
    };
}
function deserializeAddClassificationToFileRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "AddClassificationToFileRequestBody"',
        });
    }
    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 "AddClassificationToFileRequestBody"',
        });
    }
    const boxSecurityClassificationKey = val.Box__Security__Classification__Key == void 0
        ? void 0
        : val.Box__Security__Classification__Key;
    return {
        boxSecurityClassificationKey: boxSecurityClassificationKey,
    };
}
function serializeUpdateClassificationOnFileRequestBodyOpField(val) {
    return val;
}
function deserializeUpdateClassificationOnFileRequestBodyOpField(val) {
    if (val == 'replace') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize UpdateClassificationOnFileRequestBodyOpField",
    });
}
function serializeUpdateClassificationOnFileRequestBodyPathField(val) {
    return val;
}
function deserializeUpdateClassificationOnFileRequestBodyPathField(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 UpdateClassificationOnFileRequestBodyPathField",
    });
}
function serializeUpdateClassificationOnFileRequestBody(val) {
    return {
        ['op']: serializeUpdateClassificationOnFileRequestBodyOpField(val.op),
        ['path']: serializeUpdateClassificationOnFileRequestBodyPathField(val.path),
        ['value']: val.value,
    };
}
function deserializeUpdateClassificationOnFileRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateClassificationOnFileRequestBody"',
        });
    }
    if (val.op == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "op" of type "UpdateClassificationOnFileRequestBody" to be defined',
        });
    }
    const op = deserializeUpdateClassificationOnFileRequestBodyOpField(val.op);
    if (val.path == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "path" of type "UpdateClassificationOnFileRequestBody" to be defined',
        });
    }
    const path = deserializeUpdateClassificationOnFileRequestBodyPathField(val.path);
    if (val.value == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "value" of type "UpdateClassificationOnFileRequestBody" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.value)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "value" of type "UpdateClassificationOnFileRequestBody"',
        });
    }
    const value = val.value;
    return {
        op: op,
        path: path,
        value: value,
    };
}
function serializeUpdateClassificationOnFileRequestBodyInput(val) {
    return {
        ['op']: val.op == void 0
            ? val.op
            : serializeUpdateClassificationOnFileRequestBodyOpField(val.op),
        ['path']: val.path == void 0
            ? val.path
            : serializeUpdateClassificationOnFileRequestBodyPathField(val.path),
        ['value']: val.value,
    };
}
function deserializeUpdateClassificationOnFileRequestBodyInput(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateClassificationOnFileRequestBodyInput"',
        });
    }
    const op = val.op == void 0
        ? void 0
        : deserializeUpdateClassificationOnFileRequestBodyOpField(val.op);
    const path = val.path == void 0
        ? void 0
        : deserializeUpdateClassificationOnFileRequestBodyPathField(val.path);
    if (val.value == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "value" of type "UpdateClassificationOnFileRequestBodyInput" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.value)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "value" of type "UpdateClassificationOnFileRequestBodyInput"',
        });
    }
    const value = val.value;
    return {
        op: op,
        path: path,
        value: value,
    };
}
//# sourceMappingURL=fileClassifications.js.map