"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileWatermarksManager = exports.DeleteFileWatermarkHeaders = exports.UpdateFileWatermarkHeaders = exports.UpdateFileWatermarkRequestBodyWatermarkField = exports.GetFileWatermarkHeaders = exports.DeleteFileWatermarkOptionals = exports.UpdateFileWatermarkOptionals = exports.GetFileWatermarkOptionals = void 0;
exports.serializeUpdateFileWatermarkRequestBodyWatermarkImprintField = serializeUpdateFileWatermarkRequestBodyWatermarkImprintField;
exports.deserializeUpdateFileWatermarkRequestBodyWatermarkImprintField = deserializeUpdateFileWatermarkRequestBodyWatermarkImprintField;
exports.serializeUpdateFileWatermarkRequestBodyWatermarkField = serializeUpdateFileWatermarkRequestBodyWatermarkField;
exports.deserializeUpdateFileWatermarkRequestBodyWatermarkField = deserializeUpdateFileWatermarkRequestBodyWatermarkField;
exports.serializeUpdateFileWatermarkRequestBodyWatermarkFieldInput = serializeUpdateFileWatermarkRequestBodyWatermarkFieldInput;
exports.deserializeUpdateFileWatermarkRequestBodyWatermarkFieldInput = deserializeUpdateFileWatermarkRequestBodyWatermarkFieldInput;
exports.serializeUpdateFileWatermarkRequestBody = serializeUpdateFileWatermarkRequestBody;
exports.deserializeUpdateFileWatermarkRequestBody = deserializeUpdateFileWatermarkRequestBody;
const watermark_1 = require("../schemas/watermark");
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 GetFileWatermarkOptionals {
    headers = new GetFileWatermarkHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetFileWatermarkOptionals = GetFileWatermarkOptionals;
class UpdateFileWatermarkOptionals {
    headers = new UpdateFileWatermarkHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.UpdateFileWatermarkOptionals = UpdateFileWatermarkOptionals;
class DeleteFileWatermarkOptionals {
    headers = new DeleteFileWatermarkHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteFileWatermarkOptionals = DeleteFileWatermarkOptionals;
class GetFileWatermarkHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetFileWatermarkHeaders = GetFileWatermarkHeaders;
class UpdateFileWatermarkRequestBodyWatermarkField {
    /**
     * The type of watermark to apply.
     *
     * Currently only supports one option. */
    imprint = 'default';
    rawData;
    constructor(fields) {
        if (fields.imprint !== undefined) {
            this.imprint = fields.imprint;
        }
        if (fields.rawData !== undefined) {
            this.rawData = fields.rawData;
        }
    }
}
exports.UpdateFileWatermarkRequestBodyWatermarkField = UpdateFileWatermarkRequestBodyWatermarkField;
class UpdateFileWatermarkHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.UpdateFileWatermarkHeaders = UpdateFileWatermarkHeaders;
class DeleteFileWatermarkHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteFileWatermarkHeaders = DeleteFileWatermarkHeaders;
class FileWatermarksManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
       * Retrieve the watermark for a file.
       * @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 {GetFileWatermarkOptionalsInput} optionalsInput
       * @returns {Promise<Watermark>}
       */
    async getFileWatermark(fileId, optionalsInput = {}) {
        const optionals = new GetFileWatermarkOptionals({
            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), '/watermark'),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, watermark_1.deserializeWatermark)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Applies or update a watermark on a file.
       * @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 {UpdateFileWatermarkRequestBody} requestBody Request body of updateFileWatermark method
       * @param {UpdateFileWatermarkOptionalsInput} optionalsInput
       * @returns {Promise<Watermark>}
       */
    async updateFileWatermark(fileId, requestBody, optionalsInput = {}) {
        const optionals = new UpdateFileWatermarkOptionals({
            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), '/watermark'),
            method: 'PUT',
            headers: headersMap,
            data: serializeUpdateFileWatermarkRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, watermark_1.deserializeWatermark)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Removes the watermark from a file.
       * @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 {DeleteFileWatermarkOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteFileWatermark(fileId, optionalsInput = {}) {
        const optionals = new DeleteFileWatermarkOptionals({
            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), '/watermark'),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
}
exports.FileWatermarksManager = FileWatermarksManager;
function serializeUpdateFileWatermarkRequestBodyWatermarkImprintField(val) {
    return val;
}
function deserializeUpdateFileWatermarkRequestBodyWatermarkImprintField(val) {
    if (val == 'default') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize UpdateFileWatermarkRequestBodyWatermarkImprintField",
    });
}
function serializeUpdateFileWatermarkRequestBodyWatermarkField(val) {
    return {
        ['imprint']: serializeUpdateFileWatermarkRequestBodyWatermarkImprintField(val.imprint),
    };
}
function deserializeUpdateFileWatermarkRequestBodyWatermarkField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateFileWatermarkRequestBodyWatermarkField"',
        });
    }
    if (val.imprint == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "imprint" of type "UpdateFileWatermarkRequestBodyWatermarkField" to be defined',
        });
    }
    const imprint = deserializeUpdateFileWatermarkRequestBodyWatermarkImprintField(val.imprint);
    return {
        imprint: imprint,
    };
}
function serializeUpdateFileWatermarkRequestBodyWatermarkFieldInput(val) {
    return {
        ['imprint']: val.imprint == void 0
            ? val.imprint
            : serializeUpdateFileWatermarkRequestBodyWatermarkImprintField(val.imprint),
    };
}
function deserializeUpdateFileWatermarkRequestBodyWatermarkFieldInput(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateFileWatermarkRequestBodyWatermarkFieldInput"',
        });
    }
    const imprint = val.imprint == void 0
        ? void 0
        : deserializeUpdateFileWatermarkRequestBodyWatermarkImprintField(val.imprint);
    return {
        imprint: imprint,
    };
}
function serializeUpdateFileWatermarkRequestBody(val) {
    return {
        ['watermark']: serializeUpdateFileWatermarkRequestBodyWatermarkField(val.watermark),
    };
}
function deserializeUpdateFileWatermarkRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateFileWatermarkRequestBody"',
        });
    }
    if (val.watermark == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "watermark" of type "UpdateFileWatermarkRequestBody" to be defined',
        });
    }
    const watermark = deserializeUpdateFileWatermarkRequestBodyWatermarkField(val.watermark);
    return { watermark: watermark };
}
//# sourceMappingURL=fileWatermarks.js.map