"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.TicketsClient = void 0;
const BaseClient_1 = require("../../../../../../BaseClient");
const core = __importStar(require("../../../../../../core"));
const headers_1 = require("../../../../../../core/headers");
const environments = __importStar(require("../../../../../../environments"));
const handleNonStatusCodeError_1 = require("../../../../../../errors/handleNonStatusCodeError");
const errors = __importStar(require("../../../../../../errors/index"));
const serializers = __importStar(require("../../../../../../serialization/index"));
class TicketsClient {
    constructor(options) {
        this._options = (0, BaseClient_1.normalizeClientOptionsWithAuth)(options);
    }
    /**
     * Returns a list of `Ticket` objects.
     *
     * @param {Merge.ticketing.TicketsListRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.list({
     *         accountId: "account_id",
     *         assigneeIds: "assignee_ids",
     *         collectionIds: "collection_ids",
     *         completedAfter: new Date("2024-01-15T09:30:00.000Z"),
     *         completedBefore: new Date("2024-01-15T09:30:00.000Z"),
     *         contactId: "contact_id",
     *         createdAfter: new Date("2024-01-15T09:30:00.000Z"),
     *         createdBefore: new Date("2024-01-15T09:30:00.000Z"),
     *         creatorId: "creator_id",
     *         creatorIds: "creator_ids",
     *         cursor: "cD0yMDIxLTAxLTA2KzAzJTNBMjQlM0E1My40MzQzMjYlMkIwMCUzQTAw",
     *         dueAfter: new Date("2024-01-15T09:30:00.000Z"),
     *         dueBefore: new Date("2024-01-15T09:30:00.000Z"),
     *         includeDeletedData: true,
     *         includeRemoteData: true,
     *         includeRemoteFields: true,
     *         includeShellData: true,
     *         modifiedAfter: new Date("2024-01-15T09:30:00.000Z"),
     *         modifiedBefore: new Date("2024-01-15T09:30:00.000Z"),
     *         name: "name",
     *         pageSize: 1,
     *         parentTicketId: "parent_ticket_id",
     *         priority: "HIGH",
     *         remoteCreatedAfter: new Date("2024-01-15T09:30:00.000Z"),
     *         remoteCreatedBefore: new Date("2024-01-15T09:30:00.000Z"),
     *         remoteFields: "priority",
     *         remoteId: "remote_id",
     *         remoteIds: "remote_ids",
     *         remoteUpdatedAfter: new Date("2024-01-15T09:30:00.000Z"),
     *         remoteUpdatedBefore: new Date("2024-01-15T09:30:00.000Z"),
     *         showEnumOrigins: "priority",
     *         status: "",
     *         tags: "tags",
     *         ticketType: "ticket_type",
     *         ticketUrl: "ticket_url"
     *     })
     */
    list() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () {
                var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
                const { accountId, assigneeIds, collectionIds, completedAfter, completedBefore, contactId, createdAfter, createdBefore, creatorId, creatorIds, cursor, dueAfter, dueBefore, expand, includeDeletedData, includeRemoteData, includeRemoteFields, includeShellData, modifiedAfter, modifiedBefore, name, pageSize, parentTicketId, priority, remoteCreatedAfter, remoteCreatedBefore, remoteFields, remoteId, remoteIds, remoteUpdatedAfter, remoteUpdatedBefore, showEnumOrigins, status, tags, ticketType, ticketUrl, } = request;
                const _queryParams = {
                    account_id: accountId,
                    assignee_ids: assigneeIds,
                    collection_ids: collectionIds,
                    completed_after: completedAfter === null || completedAfter === void 0 ? void 0 : completedAfter.toISOString(),
                    completed_before: completedBefore === null || completedBefore === void 0 ? void 0 : completedBefore.toISOString(),
                    contact_id: contactId,
                    created_after: createdAfter === null || createdAfter === void 0 ? void 0 : createdAfter.toISOString(),
                    created_before: createdBefore === null || createdBefore === void 0 ? void 0 : createdBefore.toISOString(),
                    creator_id: creatorId,
                    creator_ids: creatorIds,
                    cursor,
                    due_after: dueAfter === null || dueAfter === void 0 ? void 0 : dueAfter.toISOString(),
                    due_before: dueBefore === null || dueBefore === void 0 ? void 0 : dueBefore.toISOString(),
                    expand: Array.isArray(expand)
                        ? expand.map((item) => serializers.ticketing.TicketsListRequestExpandItem.jsonOrThrow(item, {
                            unrecognizedObjectKeys: "strip",
                        }))
                        : expand != null
                            ? serializers.ticketing.TicketsListRequestExpandItem.jsonOrThrow(expand, {
                                unrecognizedObjectKeys: "strip",
                            })
                            : undefined,
                    include_deleted_data: includeDeletedData,
                    include_remote_data: includeRemoteData,
                    include_remote_fields: includeRemoteFields,
                    include_shell_data: includeShellData,
                    modified_after: modifiedAfter === null || modifiedAfter === void 0 ? void 0 : modifiedAfter.toISOString(),
                    modified_before: modifiedBefore === null || modifiedBefore === void 0 ? void 0 : modifiedBefore.toISOString(),
                    name,
                    page_size: pageSize,
                    parent_ticket_id: parentTicketId,
                    priority: priority != null
                        ? serializers.ticketing.TicketsListRequestPriority.jsonOrThrow(priority, {
                            unrecognizedObjectKeys: "strip",
                        })
                        : undefined,
                    remote_created_after: remoteCreatedAfter === null || remoteCreatedAfter === void 0 ? void 0 : remoteCreatedAfter.toISOString(),
                    remote_created_before: remoteCreatedBefore === null || remoteCreatedBefore === void 0 ? void 0 : remoteCreatedBefore.toISOString(),
                    remote_fields: remoteFields != null
                        ? serializers.ticketing.TicketsListRequestRemoteFields.jsonOrThrow(remoteFields, {
                            unrecognizedObjectKeys: "strip",
                        })
                        : undefined,
                    remote_id: remoteId,
                    remote_ids: remoteIds,
                    remote_updated_after: remoteUpdatedAfter === null || remoteUpdatedAfter === void 0 ? void 0 : remoteUpdatedAfter.toISOString(),
                    remote_updated_before: remoteUpdatedBefore === null || remoteUpdatedBefore === void 0 ? void 0 : remoteUpdatedBefore.toISOString(),
                    show_enum_origins: showEnumOrigins != null
                        ? serializers.ticketing.TicketsListRequestShowEnumOrigins.jsonOrThrow(showEnumOrigins, {
                            unrecognizedObjectKeys: "strip",
                        })
                        : undefined,
                    status: status != null
                        ? serializers.ticketing.TicketsListRequestStatus.jsonOrThrow(status, {
                            unrecognizedObjectKeys: "strip",
                        })
                        : undefined,
                    tags,
                    ticket_type: ticketType,
                    ticket_url: ticketUrl,
                };
                const _authRequest = yield this._options.authProvider.getAuthRequest();
                const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                    "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: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                    maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                    abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                    fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                    logging: this._options.logging,
                });
                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,
                    });
                }
                return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets");
            }));
            const dataWithRawResponse = yield list(request).withRawResponse();
            return new core.Page({
                response: dataWithRawResponse.data,
                rawResponse: dataWithRawResponse.rawResponse,
                hasNextPage: (response) => (response === null || response === void 0 ? void 0 : response.next) != null && !(typeof (response === null || response === void 0 ? void 0 : response.next) === "string" && (response === null || response === void 0 ? void 0 : response.next) === ""),
                getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.results) !== null && _a !== void 0 ? _a : []; },
                loadPage: (response) => {
                    return list(core.setObjectProperty(request, "cursor", response === null || response === void 0 ? void 0 : response.next));
                },
            });
        });
    }
    /**
     * Creates a `Ticket` object with the given values.
     *
     * @param {Merge.ticketing.TicketEndpointRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.create({
     *         isDebugMode: true,
     *         runAsync: true,
     *         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, _g, _h, _j, _k, _l, _m;
            const { isDebugMode, runAsync } = request, _body = __rest(request, ["isDebugMode", "runAsync"]);
            const _queryParams = {
                is_debug_mode: isDebugMode,
                run_async: runAsync,
            };
            const _authRequest = yield this._options.authProvider.getAuthRequest();
            const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "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: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            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,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/ticketing/v1/tickets");
        });
    }
    /**
     * Returns a `Ticket` object with the given `id`.
     *
     * @param {string} id
     * @param {Merge.ticketing.TicketsRetrieveRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.retrieve("id", {
     *         includeRemoteData: true,
     *         includeRemoteFields: true,
     *         includeShellData: true,
     *         remoteFields: "priority",
     *         showEnumOrigins: "priority"
     *     })
     */
    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, _g, _h, _j, _k, _l, _m;
            const { expand, includeRemoteData, includeRemoteFields, includeShellData, remoteFields, showEnumOrigins } = request;
            const _queryParams = {
                expand: Array.isArray(expand)
                    ? expand.map((item) => serializers.ticketing.TicketsRetrieveRequestExpandItem.jsonOrThrow(item, {
                        unrecognizedObjectKeys: "strip",
                    }))
                    : expand != null
                        ? serializers.ticketing.TicketsRetrieveRequestExpandItem.jsonOrThrow(expand, {
                            unrecognizedObjectKeys: "strip",
                        })
                        : undefined,
                include_remote_data: includeRemoteData,
                include_remote_fields: includeRemoteFields,
                include_shell_data: includeShellData,
                remote_fields: remoteFields != null
                    ? serializers.ticketing.TicketsRetrieveRequestRemoteFields.jsonOrThrow(remoteFields, {
                        unrecognizedObjectKeys: "strip",
                    })
                    : undefined,
                show_enum_origins: showEnumOrigins != null
                    ? serializers.ticketing.TicketsRetrieveRequestShowEnumOrigins.jsonOrThrow(showEnumOrigins, {
                        unrecognizedObjectKeys: "strip",
                    })
                    : undefined,
            };
            const _authRequest = yield this._options.authProvider.getAuthRequest();
            const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "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/${core.url.encodePathParam(id)}`),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            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,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets/{id}");
        });
    }
    /**
     * Updates a `Ticket` object with the given `id`.
     *
     * @param {string} id
     * @param {Merge.ticketing.PatchedTicketEndpointRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.partialUpdate("id", {
     *         isDebugMode: true,
     *         runAsync: true,
     *         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, _g, _h, _j, _k, _l, _m;
            const { isDebugMode, runAsync } = request, _body = __rest(request, ["isDebugMode", "runAsync"]);
            const _queryParams = {
                is_debug_mode: isDebugMode,
                run_async: runAsync,
            };
            const _authRequest = yield this._options.authProvider.getAuthRequest();
            const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "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/${core.url.encodePathParam(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: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            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,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "PATCH", "/ticketing/v1/tickets/{id}");
        });
    }
    /**
     * 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} ticket_id
     * @param {Merge.ticketing.TicketsViewersListRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.viewersList("ticket_id", {
     *         cursor: "cD0yMDIxLTAxLTA2KzAzJTNBMjQlM0E1My40MzQzMjYlMkIwMCUzQTAw",
     *         includeDeletedData: true,
     *         includeRemoteData: true,
     *         includeShellData: true,
     *         pageSize: 1
     *     })
     */
    viewersList(ticket_id_1) {
        return __awaiter(this, arguments, void 0, function* (ticket_id, request = {}, requestOptions) {
            const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () {
                var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
                const { cursor, expand, includeDeletedData, includeRemoteData, includeShellData, pageSize } = request;
                const _queryParams = {
                    cursor,
                    expand: Array.isArray(expand)
                        ? expand.map((item) => serializers.ticketing.TicketsViewersListRequestExpandItem.jsonOrThrow(item, {
                            unrecognizedObjectKeys: "strip",
                        }))
                        : expand != null
                            ? serializers.ticketing.TicketsViewersListRequestExpandItem.jsonOrThrow(expand, {
                                unrecognizedObjectKeys: "strip",
                            })
                            : undefined,
                    include_deleted_data: includeDeletedData,
                    include_remote_data: includeRemoteData,
                    include_shell_data: includeShellData,
                    page_size: pageSize,
                };
                const _authRequest = yield this._options.authProvider.getAuthRequest();
                const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                    "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/${core.url.encodePathParam(ticket_id)}/viewers`),
                    method: "GET",
                    headers: _headers,
                    queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                    timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                    maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                    abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                    fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                    logging: this._options.logging,
                });
                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,
                    });
                }
                return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets/{ticket_id}/viewers");
            }));
            const dataWithRawResponse = yield list(request).withRawResponse();
            return new core.Page({
                response: dataWithRawResponse.data,
                rawResponse: dataWithRawResponse.rawResponse,
                hasNextPage: (response) => (response === null || response === void 0 ? void 0 : response.next) != null && !(typeof (response === null || response === void 0 ? void 0 : response.next) === "string" && (response === null || response === void 0 ? void 0 : response.next) === ""),
                getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.results) !== null && _a !== void 0 ? _a : []; },
                loadPage: (response) => {
                    return list(core.setObjectProperty(request, "cursor", response === null || response === void 0 ? void 0 : response.next));
                },
            });
        });
    }
    /**
     * Returns a list of `Ticket` objects.
     */
    liveSearchRetrieve(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__liveSearchRetrieve(request, requestOptions));
    }
    __liveSearchRetrieve() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { assigneeIds, assignees, collectionIds, collections, includeDeletedData, includeRemoteFields, includeShellData, name, remoteCursor, remoteFields, showEnumOrigins, status, ticketUrl, } = request;
            const _queryParams = {
                assignee_ids: assigneeIds,
                assignees,
                collection_ids: collectionIds,
                collections,
                include_deleted_data: includeDeletedData,
                include_remote_fields: includeRemoteFields,
                include_shell_data: includeShellData,
                name,
                remote_cursor: remoteCursor,
                remote_fields: remoteFields != null
                    ? serializers.ticketing.TicketsLiveSearchRetrieveRequestRemoteFields.jsonOrThrow(remoteFields, {
                        unrecognizedObjectKeys: "strip",
                    })
                    : undefined,
                show_enum_origins: showEnumOrigins != null
                    ? serializers.ticketing.TicketsLiveSearchRetrieveRequestShowEnumOrigins.jsonOrThrow(showEnumOrigins, { unrecognizedObjectKeys: "strip" })
                    : undefined,
                status,
                ticket_url: ticketUrl,
            };
            const _authRequest = yield this._options.authProvider.getAuthRequest();
            const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "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/live-search"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                responseType: "streaming",
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return { data: _response.body, rawResponse: _response.rawResponse };
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                    rawResponse: _response.rawResponse,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets/live-search");
        });
    }
    /**
     * Returns metadata for `Ticket` PATCHs.
     *
     * @param {string} id
     * @param {TicketsClient.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, _g, _h, _j, _k, _l, _m;
            const _authRequest = yield this._options.authProvider.getAuthRequest();
            const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "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/${core.url.encodePathParam(id)}`),
                method: "GET",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            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,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets/meta/patch/{id}");
        });
    }
    /**
     * Returns metadata for `Ticket` POSTs.
     *
     * @param {Merge.ticketing.TicketsMetaPostRetrieveRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.metaPostRetrieve({
     *         collectionId: "collection_id",
     *         ticketType: "ticket_type"
     *     })
     */
    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, _g, _h, _j, _k, _l, _m;
            const { collectionId, ticketType } = request;
            const _queryParams = {
                collection_id: collectionId,
                ticket_type: ticketType,
            };
            const _authRequest = yield this._options.authProvider.getAuthRequest();
            const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "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: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            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,
                });
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets/meta/post");
        });
    }
    /**
     * Returns a list of `RemoteFieldClass` objects.
     *
     * @param {Merge.ticketing.TicketsRemoteFieldClassesListRequest} request
     * @param {TicketsClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.ticketing.tickets.remoteFieldClassesList({
     *         cursor: "cD0yMDIxLTAxLTA2KzAzJTNBMjQlM0E1My40MzQzMjYlMkIwMCUzQTAw",
     *         ids: "ids",
     *         includeDeletedData: true,
     *         includeRemoteData: true,
     *         includeShellData: true,
     *         isCommonModelField: true,
     *         isCustom: true,
     *         pageSize: 1
     *     })
     */
    remoteFieldClassesList() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () {
                var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
                const { cursor, ids, includeDeletedData, includeRemoteData, includeShellData, isCommonModelField, isCustom, pageSize, } = request;
                const _queryParams = {
                    cursor,
                    ids,
                    include_deleted_data: includeDeletedData,
                    include_remote_data: includeRemoteData,
                    include_shell_data: includeShellData,
                    is_common_model_field: isCommonModelField,
                    is_custom: isCustom,
                    page_size: pageSize,
                };
                const _authRequest = yield this._options.authProvider.getAuthRequest();
                const _headers = (0, headers_1.mergeHeaders)(_authRequest.headers, (_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                    "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: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 60) * 1000,
                    maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                    abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                    fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                    logging: this._options.logging,
                });
                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,
                    });
                }
                return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/ticketing/v1/tickets/remote-field-classes");
            }));
            const dataWithRawResponse = yield list(request).withRawResponse();
            return new core.Page({
                response: dataWithRawResponse.data,
                rawResponse: dataWithRawResponse.rawResponse,
                hasNextPage: (response) => (response === null || response === void 0 ? void 0 : response.next) != null && !(typeof (response === null || response === void 0 ? void 0 : response.next) === "string" && (response === null || response === void 0 ? void 0 : response.next) === ""),
                getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.results) !== null && _a !== void 0 ? _a : []; },
                loadPage: (response) => {
                    return list(core.setObjectProperty(request, "cursor", response === null || response === void 0 ? void 0 : response.next));
                },
            });
        });
    }
}
exports.TicketsClient = TicketsClient;
