"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 (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Employees = void 0;
const environments = __importStar(require("../../../../../../environments"));
const core = __importStar(require("../../../../../../core"));
const url_join_1 = __importDefault(require("url-join"));
const serializers = __importStar(require("../../../../../../serialization/index"));
const errors = __importStar(require("../../../../../../errors/index"));
class Employees {
    constructor(_options) {
        this._options = _options;
    }
    /**
     * Returns a list of `Employee` objects.
     *
     * @param {Merge.hris.EmployeesListRequest} request
     * @param {Employees.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.hris.employees.list()
     */
    list(request = {}, requestOptions) {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function* () {
            const { companyId, createdAfter, createdBefore, cursor, displayFullName, employmentStatus, employmentType, expand, firstName, groups, homeLocationId, includeDeletedData, includeRemoteData, includeSensitiveFields, includeShellData, jobTitle, lastName, managerId, modifiedAfter, modifiedBefore, pageSize, payGroupId, personalEmail, remoteFields, remoteId, showEnumOrigins, startedAfter, startedBefore, teamId, terminatedAfter, terminatedBefore, workEmail, workLocationId, } = request;
            const _queryParams = {};
            if (companyId != null) {
                _queryParams["company_id"] = companyId;
            }
            if (createdAfter != null) {
                _queryParams["created_after"] = createdAfter.toISOString();
            }
            if (createdBefore != null) {
                _queryParams["created_before"] = createdBefore.toISOString();
            }
            if (cursor != null) {
                _queryParams["cursor"] = cursor;
            }
            if (displayFullName != null) {
                _queryParams["display_full_name"] = displayFullName;
            }
            if (employmentStatus != null) {
                _queryParams["employment_status"] = employmentStatus;
            }
            if (employmentType != null) {
                _queryParams["employment_type"] = employmentType;
            }
            if (expand != null) {
                _queryParams["expand"] = expand;
            }
            if (firstName != null) {
                _queryParams["first_name"] = firstName;
            }
            if (groups != null) {
                _queryParams["groups"] = groups;
            }
            if (homeLocationId != null) {
                _queryParams["home_location_id"] = homeLocationId;
            }
            if (includeDeletedData != null) {
                _queryParams["include_deleted_data"] = includeDeletedData.toString();
            }
            if (includeRemoteData != null) {
                _queryParams["include_remote_data"] = includeRemoteData.toString();
            }
            if (includeSensitiveFields != null) {
                _queryParams["include_sensitive_fields"] = includeSensitiveFields.toString();
            }
            if (includeShellData != null) {
                _queryParams["include_shell_data"] = includeShellData.toString();
            }
            if (jobTitle != null) {
                _queryParams["job_title"] = jobTitle;
            }
            if (lastName != null) {
                _queryParams["last_name"] = lastName;
            }
            if (managerId != null) {
                _queryParams["manager_id"] = managerId;
            }
            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 (payGroupId != null) {
                _queryParams["pay_group_id"] = payGroupId;
            }
            if (personalEmail != null) {
                _queryParams["personal_email"] = personalEmail;
            }
            if (remoteFields != null) {
                _queryParams["remote_fields"] = remoteFields;
            }
            if (remoteId != null) {
                _queryParams["remote_id"] = remoteId;
            }
            if (showEnumOrigins != null) {
                _queryParams["show_enum_origins"] = showEnumOrigins;
            }
            if (startedAfter != null) {
                _queryParams["started_after"] = startedAfter.toISOString();
            }
            if (startedBefore != null) {
                _queryParams["started_before"] = startedBefore.toISOString();
            }
            if (teamId != null) {
                _queryParams["team_id"] = teamId;
            }
            if (terminatedAfter != null) {
                _queryParams["terminated_after"] = terminatedAfter.toISOString();
            }
            if (terminatedBefore != null) {
                _queryParams["terminated_before"] = terminatedBefore.toISOString();
            }
            if (workEmail != null) {
                _queryParams["work_email"] = workEmail;
            }
            if (workLocationId != null) {
                _queryParams["work_location_id"] = workLocationId;
            }
            const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
                url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.MergeEnvironment.Production, "hris/v1/employees"),
                method: "GET",
                headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Account-Token": (yield core.Supplier.get(this._options.accountToken)) != null
                        ? yield core.Supplier.get(this._options.accountToken)
                        : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@mergeapi/merge-node-client", "X-Fern-SDK-Version": "1.1.4", "User-Agent": "@mergeapi/merge-node-client/1.1.4", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                contentType: "application/json",
                queryParameters: _queryParams,
                requestType: "json",
                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 serializers.hris.PaginatedEmployeeList.parseOrThrow(_response.body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                    skipValidation: true,
                    breadcrumbsPrefix: ["response"],
                });
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /hris/v1/employees.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    /**
     * Creates an `Employee` object with the given values.
     *
     * @param {Merge.hris.EmployeeEndpointRequest} request
     * @param {Employees.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.hris.employees.create({
     *         model: {}
     *     })
     */
    create(request, requestOptions) {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function* () {
            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();
            }
            const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
                url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.MergeEnvironment.Production, "hris/v1/employees"),
                method: "POST",
                headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Account-Token": (yield core.Supplier.get(this._options.accountToken)) != null
                        ? yield core.Supplier.get(this._options.accountToken)
                        : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@mergeapi/merge-node-client", "X-Fern-SDK-Version": "1.1.4", "User-Agent": "@mergeapi/merge-node-client/1.1.4", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                contentType: "application/json",
                queryParameters: _queryParams,
                requestType: "json",
                body: serializers.hris.EmployeeEndpointRequest.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 serializers.hris.EmployeeResponse.parseOrThrow(_response.body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                    skipValidation: true,
                    breadcrumbsPrefix: ["response"],
                });
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling POST /hris/v1/employees.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    /**
     * Returns an `Employee` object with the given `id`.
     *
     * @param {string} id
     * @param {Merge.hris.EmployeesRetrieveRequest} request
     * @param {Employees.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.hris.employees.retrieve("id")
     */
    retrieve(id, request = {}, requestOptions) {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function* () {
            const { expand, includeRemoteData, includeSensitiveFields, remoteFields, showEnumOrigins } = request;
            const _queryParams = {};
            if (expand != null) {
                _queryParams["expand"] = expand;
            }
            if (includeRemoteData != null) {
                _queryParams["include_remote_data"] = includeRemoteData.toString();
            }
            if (includeSensitiveFields != null) {
                _queryParams["include_sensitive_fields"] = includeSensitiveFields.toString();
            }
            if (remoteFields != null) {
                _queryParams["remote_fields"] = remoteFields;
            }
            if (showEnumOrigins != null) {
                _queryParams["show_enum_origins"] = showEnumOrigins;
            }
            const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
                url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.MergeEnvironment.Production, `hris/v1/employees/${encodeURIComponent(id)}`),
                method: "GET",
                headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Account-Token": (yield core.Supplier.get(this._options.accountToken)) != null
                        ? yield core.Supplier.get(this._options.accountToken)
                        : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@mergeapi/merge-node-client", "X-Fern-SDK-Version": "1.1.4", "User-Agent": "@mergeapi/merge-node-client/1.1.4", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                contentType: "application/json",
                queryParameters: _queryParams,
                requestType: "json",
                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 serializers.hris.Employee.parseOrThrow(_response.body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                    skipValidation: true,
                    breadcrumbsPrefix: ["response"],
                });
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /hris/v1/employees/{id}.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    /**
     * Ignores a specific row based on the `model_id` in the url. These records will have their properties set to null, and will not be updated in future syncs. The "reason" and "message" fields in the request body will be stored for audit purposes.
     *
     * @param {string} modelId
     * @param {Merge.hris.IgnoreCommonModelRequest} request
     * @param {Employees.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.hris.employees.ignoreCreate("model_id", {
     *         reason: "GENERAL_CUSTOMER_REQUEST"
     *     })
     */
    ignoreCreate(modelId, request, requestOptions) {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function* () {
            const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
                url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.MergeEnvironment.Production, `hris/v1/employees/ignore/${encodeURIComponent(modelId)}`),
                method: "POST",
                headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Account-Token": (yield core.Supplier.get(this._options.accountToken)) != null
                        ? yield core.Supplier.get(this._options.accountToken)
                        : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@mergeapi/merge-node-client", "X-Fern-SDK-Version": "1.1.4", "User-Agent": "@mergeapi/merge-node-client/1.1.4", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                contentType: "application/json",
                requestType: "json",
                body: serializers.hris.IgnoreCommonModelRequest.jsonOrThrow(request, { 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;
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling POST /hris/v1/employees/ignore/{model_id}.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    /**
     * Returns metadata for `Employee` POSTs.
     *
     * @param {Employees.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.hris.employees.metaPostRetrieve()
     */
    metaPostRetrieve(requestOptions) {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function* () {
            const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
                url: (0, url_join_1.default)((_b = (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.MergeEnvironment.Production, "hris/v1/employees/meta/post"),
                method: "GET",
                headers: Object.assign({ Authorization: yield this._getAuthorizationHeader(), "X-Account-Token": (yield core.Supplier.get(this._options.accountToken)) != null
                        ? yield core.Supplier.get(this._options.accountToken)
                        : undefined, "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "@mergeapi/merge-node-client", "X-Fern-SDK-Version": "1.1.4", "User-Agent": "@mergeapi/merge-node-client/1.1.4", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
                contentType: "application/json",
                requestType: "json",
                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 serializers.hris.MetaResponse.parseOrThrow(_response.body, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                    skipValidation: true,
                    breadcrumbsPrefix: ["response"],
                });
            }
            if (_response.error.reason === "status-code") {
                throw new errors.MergeError({
                    statusCode: _response.error.statusCode,
                    body: _response.error.body,
                });
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.MergeError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                    });
                case "timeout":
                    throw new errors.MergeTimeoutError("Timeout exceeded when calling GET /hris/v1/employees/meta/post.");
                case "unknown":
                    throw new errors.MergeError({
                        message: _response.error.errorMessage,
                    });
            }
        });
    }
    _getAuthorizationHeader() {
        return __awaiter(this, void 0, void 0, function* () {
            return `Bearer ${yield core.Supplier.get(this._options.apiKey)}`;
        });
    }
}
exports.Employees = Employees;
