"use strict";
/**
 * This file was auto-generated by Fern from our API Definition.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tickets = void 0;
const environments = __importStar(require("../../../../../../environments"));
const core = __importStar(require("../../../../../../core"));
const serializers = __importStar(require("../../../../../../serialization/index"));
const headers_1 = require("../../../../../../core/headers");
const errors = __importStar(require("../../../../../../errors/index"));
class Tickets {
    constructor(_options) {
        this._options = _options;
    }
    /**
     * Returns a list of `Ticket` objects.
     *
     * @param {Merge.ticketing.TicketsListRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.list({
     *         cursor: "cD0yMDIxLTAxLTA2KzAzJTNBMjQlM0E1My40MzQzMjYlMkIwMCUzQTAw"
     *     })
     */
    list(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__list(request, requestOptions));
    }
    __list() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f;
            const { accountId, assigneeIds, collectionIds, completedAfter, completedBefore, contactId, createdAfter, createdBefore, cursor, dueAfter, dueBefore, expand, includeDeletedData, includeRemoteData, includeRemoteFields, includeShellData, modifiedAfter, modifiedBefore, pageSize, parentTicketId, priority, remoteCreatedAfter, remoteCreatedBefore, remoteFields, remoteId, remoteUpdatedAfter, remoteUpdatedBefore, showEnumOrigins, status, tags, ticketType, ticketUrl, } = request;
            const _queryParams = {};
            if (accountId != null) {
                _queryParams["account_id"] = accountId;
            }
            if (assigneeIds != null) {
                _queryParams["assignee_ids"] = assigneeIds;
            }
            if (collectionIds != null) {
                _queryParams["collection_ids"] = collectionIds;
            }
            if (completedAfter != null) {
                _queryParams["completed_after"] = completedAfter.toISOString();
            }
            if (completedBefore != null) {
                _queryParams["completed_before"] = completedBefore.toISOString();
            }
            if (contactId != null) {
                _queryParams["contact_id"] = contactId;
            }
            if (createdAfter != null) {
                _queryParams["created_after"] = createdAfter.toISOString();
            }
            if (createdBefore != null) {
                _queryParams["created_before"] = createdBefore.toISOString();
            }
            if (cursor != null) {
                _queryParams["cursor"] = cursor;
            }
            if (dueAfter != null) {
                _queryParams["due_after"] = dueAfter.toISOString();
            }
            if (dueBefore != null) {
                _queryParams["due_before"] = dueBefore.toISOString();
            }
            if (expand != null) {
                _queryParams["expand"] = serializers.ticketing.TicketsListRequestExpand.jsonOrThrow(expand, {
                    unrecognizedObjectKeys: "strip",
                });
            }
            if (includeDeletedData != null) {
                _queryParams["include_deleted_data"] = includeDeletedData.toString();
            }
            if (includeRemoteData != null) {
                _queryParams["include_remote_data"] = includeRemoteData.toString();
            }
            if (includeRemoteFields != null) {
                _queryParams["include_remote_fields"] = includeRemoteFields.toString();
            }
            if (includeShellData != null) {
                _queryParams["include_shell_data"] = includeShellData.toString();
            }
            if (modifiedAfter != null) {
                _queryParams["modified_after"] = modifiedAfter.toISOString();
            }
            if (modifiedBefore != null) {
                _queryParams["modified_before"] = modifiedBefore.toISOString();
            }
            if (pageSize != null) {
                _queryParams["page_size"] = pageSize.toString();
            }
            if (parentTicketId != null) {
                _queryParams["parent_ticket_id"] = parentTicketId;
            }
            if (priority != null) {
                _queryParams["priority"] = serializers.ticketing.TicketsListRequestPriority.jsonOrThrow(priority, {
                    unrecognizedObjectKeys: "strip",
                });
            }
            if (remoteCreatedAfter != null) {
                _queryParams["remote_created_after"] = remoteCreatedAfter.toISOString();
            }
            if (remoteCreatedBefore != null) {
                _queryParams["remote_created_before"] = remoteCreatedBefore.toISOString();
            }
            if (remoteFields != null) {
                _queryParams["remote_fields"] = serializers.ticketing.TicketsListRequestRemoteFields.jsonOrThrow(remoteFields, { unrecognizedObjectKeys: "strip" });
            }
            if (remoteId != null) {
                _queryParams["remote_id"] = remoteId;
            }
            if (remoteUpdatedAfter != null) {
                _queryParams["remote_updated_after"] = remoteUpdatedAfter.toISOString();
            }
            if (remoteUpdatedBefore != null) {
                _queryParams["remote_updated_before"] = remoteUpdatedBefore.toISOString();
            }
            if (showEnumOrigins != null) {
                _queryParams["show_enum_origins"] = serializers.ticketing.TicketsListRequestShowEnumOrigins.jsonOrThrow(showEnumOrigins, { unrecognizedObjectKeys: "strip" });
            }
            if (status != null) {
                _queryParams["status"] = status;
            }
            if (tags != null) {
                _queryParams["tags"] = tags;
            }
            if (ticketType != null) {
                _queryParams["ticket_type"] = ticketType;
            }
            if (ticketUrl != null) {
                _queryParams["ticket_url"] = ticketUrl;
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, "ticketing/v1/tickets"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.PaginatedTicketList.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /ticketing/v1/tickets.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Creates a `Ticket` object with the given values.
     *
     * @param {Merge.ticketing.TicketEndpointRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.create({
     *         model: {}
     *     })
     */
    create(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions));
    }
    __create(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f;
            const { isDebugMode, runAsync } = request, _body = __rest(request, ["isDebugMode", "runAsync"]);
            const _queryParams = {};
            if (isDebugMode != null) {
                _queryParams["is_debug_mode"] = isDebugMode.toString();
            }
            if (runAsync != null) {
                _queryParams["run_async"] = runAsync.toString();
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, "ticketing/v1/tickets"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                requestType: "json",
                body: serializers.ticketing.TicketEndpointRequest.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.TicketResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling POST /ticketing/v1/tickets.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns a `Ticket` object with the given `id`.
     *
     * @param {string} id
     * @param {Merge.ticketing.TicketsRetrieveRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.retrieve("id")
     */
    retrieve(id, request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__retrieve(id, request, requestOptions));
    }
    __retrieve(id_1) {
        return __awaiter(this, arguments, void 0, function* (id, request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f;
            const { expand, includeRemoteData, includeRemoteFields, includeShellData, remoteFields, showEnumOrigins } = request;
            const _queryParams = {};
            if (expand != null) {
                _queryParams["expand"] = serializers.ticketing.TicketsRetrieveRequestExpand.jsonOrThrow(expand, {
                    unrecognizedObjectKeys: "strip",
                });
            }
            if (includeRemoteData != null) {
                _queryParams["include_remote_data"] = includeRemoteData.toString();
            }
            if (includeRemoteFields != null) {
                _queryParams["include_remote_fields"] = includeRemoteFields.toString();
            }
            if (includeShellData != null) {
                _queryParams["include_shell_data"] = includeShellData.toString();
            }
            if (remoteFields != null) {
                _queryParams["remote_fields"] = serializers.ticketing.TicketsRetrieveRequestRemoteFields.jsonOrThrow(remoteFields, { unrecognizedObjectKeys: "strip" });
            }
            if (showEnumOrigins != null) {
                _queryParams["show_enum_origins"] = serializers.ticketing.TicketsRetrieveRequestShowEnumOrigins.jsonOrThrow(showEnumOrigins, { unrecognizedObjectKeys: "strip" });
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, `ticketing/v1/tickets/${encodeURIComponent(id)}`),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.Ticket.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /ticketing/v1/tickets/{id}.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Updates a `Ticket` object with the given `id`.
     *
     * @param {string} id
     * @param {Merge.ticketing.PatchedTicketEndpointRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.partialUpdate("id", {
     *         model: {}
     *     })
     */
    partialUpdate(id, request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__partialUpdate(id, request, requestOptions));
    }
    __partialUpdate(id, request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f;
            const { isDebugMode, runAsync } = request, _body = __rest(request, ["isDebugMode", "runAsync"]);
            const _queryParams = {};
            if (isDebugMode != null) {
                _queryParams["is_debug_mode"] = isDebugMode.toString();
            }
            if (runAsync != null) {
                _queryParams["run_async"] = runAsync.toString();
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, `ticketing/v1/tickets/${encodeURIComponent(id)}`),
                method: "PATCH",
                headers: _headers,
                contentType: "application/json",
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                requestType: "json",
                body: serializers.ticketing.PatchedTicketEndpointRequest.jsonOrThrow(_body, {
                    unrecognizedObjectKeys: "strip",
                }),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.TicketResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling PATCH /ticketing/v1/tickets/{id}.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns a list of `Viewer` objects that point to a User id or Team id that is either an assignee or viewer on a `Ticket` with the given id. [Learn more.](https://help.merge.dev/en/articles/10333658-ticketing-access-control-list-acls)
     *
     * @param {string} ticketId
     * @param {Merge.ticketing.TicketsViewersListRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.viewersList("ticket_id", {
     *         cursor: "cD0yMDIxLTAxLTA2KzAzJTNBMjQlM0E1My40MzQzMjYlMkIwMCUzQTAw"
     *     })
     */
    viewersList(ticketId, request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__viewersList(ticketId, request, requestOptions));
    }
    __viewersList(ticketId_1) {
        return __awaiter(this, arguments, void 0, function* (ticketId, request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f;
            const { cursor, expand, includeDeletedData, includeRemoteData, includeShellData, pageSize } = request;
            const _queryParams = {};
            if (cursor != null) {
                _queryParams["cursor"] = cursor;
            }
            if (expand != null) {
                _queryParams["expand"] = serializers.ticketing.TicketsViewersListRequestExpand.jsonOrThrow(expand, {
                    unrecognizedObjectKeys: "strip",
                });
            }
            if (includeDeletedData != null) {
                _queryParams["include_deleted_data"] = includeDeletedData.toString();
            }
            if (includeRemoteData != null) {
                _queryParams["include_remote_data"] = includeRemoteData.toString();
            }
            if (includeShellData != null) {
                _queryParams["include_shell_data"] = includeShellData.toString();
            }
            if (pageSize != null) {
                _queryParams["page_size"] = pageSize.toString();
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, `ticketing/v1/tickets/${encodeURIComponent(ticketId)}/viewers`),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.PaginatedViewerList.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /ticketing/v1/tickets/{ticket_id}/viewers.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns metadata for `Ticket` PATCHs.
     *
     * @param {string} id
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.metaPatchRetrieve("id")
     */
    metaPatchRetrieve(id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__metaPatchRetrieve(id, requestOptions));
    }
    __metaPatchRetrieve(id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f;
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, `ticketing/v1/tickets/meta/patch/${encodeURIComponent(id)}`),
                method: "GET",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.MetaResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /ticketing/v1/tickets/meta/patch/{id}.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns metadata for `Ticket` POSTs.
     *
     * @param {Merge.ticketing.TicketsMetaPostRetrieveRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.metaPostRetrieve()
     */
    metaPostRetrieve(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__metaPostRetrieve(request, requestOptions));
    }
    __metaPostRetrieve() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f;
            const { collectionId, ticketType } = request;
            const _queryParams = {};
            if (collectionId != null) {
                _queryParams["collection_id"] = collectionId;
            }
            if (ticketType != null) {
                _queryParams["ticket_type"] = ticketType;
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, "ticketing/v1/tickets/meta/post"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.MetaResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /ticketing/v1/tickets/meta/post.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns a list of `RemoteFieldClass` objects.
     *
     * @param {Merge.ticketing.TicketsRemoteFieldClassesListRequest} request
     * @param {Tickets.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.remoteFieldClassesList({
     *         cursor: "cD0yMDIxLTAxLTA2KzAzJTNBMjQlM0E1My40MzQzMjYlMkIwMCUzQTAw"
     *     })
     */
    remoteFieldClassesList(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__remoteFieldClassesList(request, requestOptions));
    }
    __remoteFieldClassesList() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f;
            const { cursor, ids, includeDeletedData, includeRemoteData, includeShellData, isCommonModelField, isCustom, pageSize, } = request;
            const _queryParams = {};
            if (cursor != null) {
                _queryParams["cursor"] = cursor;
            }
            if (ids != null) {
                _queryParams["ids"] = ids;
            }
            if (includeDeletedData != null) {
                _queryParams["include_deleted_data"] = includeDeletedData.toString();
            }
            if (includeRemoteData != null) {
                _queryParams["include_remote_data"] = includeRemoteData.toString();
            }
            if (includeShellData != null) {
                _queryParams["include_shell_data"] = includeShellData.toString();
            }
            if (isCommonModelField != null) {
                _queryParams["is_common_model_field"] = isCommonModelField.toString();
            }
            if (isCustom != null) {
                _queryParams["is_custom"] = isCustom.toString();
            }
            if (pageSize != null) {
                _queryParams["page_size"] = pageSize.toString();
            }
            let _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Account-Token": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.accountToken) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.accountToken,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.MergeEnvironment.Production, "ticketing/v1/tickets/remote-field-classes"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
                maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
            });
            if (_response.ok) {
                return {
                    data: serializers.ticketing.PaginatedRemoteFieldClassList.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /ticketing/v1/tickets/remote-field-classes.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    _getAuthorizationHeader() {
        return __awaiter(this, void 0, void 0, function* () {
            return `Bearer ${yield core.Supplier.get(this._options.apiKey)}`;
        });
    }
}
exports.Tickets = Tickets;
