"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignTemplatesManager = exports.GetSignTemplateByIdHeaders = exports.GetSignTemplatesHeaders = exports.GetSignTemplateByIdOptionals = void 0;
const signTemplates_1 = require("../schemas/signTemplates");
const signTemplate_1 = require("../schemas/signTemplate");
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 GetSignTemplateByIdOptionals {
    headers = new GetSignTemplateByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetSignTemplateByIdOptionals = GetSignTemplateByIdOptionals;
class GetSignTemplatesHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetSignTemplatesHeaders = GetSignTemplatesHeaders;
class GetSignTemplateByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetSignTemplateByIdHeaders = GetSignTemplateByIdHeaders;
class SignTemplatesManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
     * Gets Box Sign templates created by a user.
     * @param {GetSignTemplatesQueryParams} queryParams Query parameters of getSignTemplates method
     * @param {GetSignTemplatesHeadersInput} headersInput Headers of getSignTemplates method
     * @param {CancellationToken} cancellationToken Token used for request cancellation.
     * @returns {Promise<SignTemplates>}
     */
    async getSignTemplates(queryParams = {}, headersInput = new GetSignTemplatesHeaders({}), cancellationToken) {
        const headers = new GetSignTemplatesHeaders({
            extraHeaders: headersInput.extraHeaders,
        });
        const queryParamsMap = (0, utils_1.prepareParams)({
            ['marker']: (0, utils_2.toString)(queryParams.marker),
            ['limit']: (0, utils_2.toString)(queryParams.limit),
        });
        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/sign_templates'),
            method: 'GET',
            params: queryParamsMap,
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, signTemplates_1.deserializeSignTemplates)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Fetches details of a specific Box Sign template.
       * @param {string} templateId The ID of a Box Sign template.
      Example: "123075213-7d117509-8f05-42e4-a5ef-5190a319d41d"
       * @param {GetSignTemplateByIdOptionalsInput} optionalsInput
       * @returns {Promise<SignTemplate>}
       */
    async getSignTemplateById(templateId, optionalsInput = {}) {
        const optionals = new GetSignTemplateByIdOptionals({
            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/sign_templates/', (0, utils_2.toString)(templateId)),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, signTemplate_1.deserializeSignTemplate)(response.data),
            rawData: response.data,
        };
    }
}
exports.SignTemplatesManager = SignTemplatesManager;
//# sourceMappingURL=signTemplates.js.map