"use strict";
/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */
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;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.DownloadEmployeeDocumentAcceptEnum = void 0;
exports.hrisDownloadEmployeeDocument = hrisDownloadEmployeeDocument;
const encodings_js_1 = require("../lib/encodings.js");
const M = __importStar(require("../lib/matchers.js"));
const primitives_js_1 = require("../lib/primitives.js");
const schemas_js_1 = require("../lib/schemas.js");
const security_js_1 = require("../lib/security.js");
const url_js_1 = require("../lib/url.js");
const errors = __importStar(require("../sdk/models/errors/index.js"));
const operations = __importStar(require("../sdk/models/operations/index.js"));
const async_js_1 = require("../sdk/types/async.js");
var DownloadEmployeeDocumentAcceptEnum;
(function (DownloadEmployeeDocumentAcceptEnum) {
    DownloadEmployeeDocumentAcceptEnum["applicationJson"] = "application/json";
    DownloadEmployeeDocumentAcceptEnum["textCsv"] = "text/csv";
    DownloadEmployeeDocumentAcceptEnum["textPlain"] = "text/plain";
    DownloadEmployeeDocumentAcceptEnum["applicationGzip"] = "application/gzip";
    DownloadEmployeeDocumentAcceptEnum["applicationMsword"] = "application/msword";
    DownloadEmployeeDocumentAcceptEnum["applicationOctetStream"] = "application/octet-stream";
    DownloadEmployeeDocumentAcceptEnum["applicationPdf"] = "application/pdf";
    DownloadEmployeeDocumentAcceptEnum["applicationRtf"] = "application/rtf";
    DownloadEmployeeDocumentAcceptEnum["applicationVndMsExcel"] = "application/vnd.ms-excel";
    DownloadEmployeeDocumentAcceptEnum["applicationVndMsOutlook"] = "application/vnd.ms-outlook";
    DownloadEmployeeDocumentAcceptEnum["applicationVndMsPowerpoint"] = "application/vnd.ms-powerpoint";
    DownloadEmployeeDocumentAcceptEnum["applicationVndOasisOpendocumentPresentation"] = "application/vnd.oasis.opendocument.presentation";
    DownloadEmployeeDocumentAcceptEnum["applicationVndOasisOpendocumentSpreadsheet"] = "application/vnd.oasis.opendocument.spreadsheet";
    DownloadEmployeeDocumentAcceptEnum["applicationVndOasisOpendocumentText"] = "application/vnd.oasis.opendocument.text";
    DownloadEmployeeDocumentAcceptEnum["applicationVndOpenxmlformatsOfficedocumentPresentationmlPresentation"] = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
    DownloadEmployeeDocumentAcceptEnum["applicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    DownloadEmployeeDocumentAcceptEnum["applicationVndOpenxmlformatsOfficedocumentWordprocessingmlDocument"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
    DownloadEmployeeDocumentAcceptEnum["applicationX7zCompressed"] = "application/x-7z-compressed";
    DownloadEmployeeDocumentAcceptEnum["applicationXRarCompressed"] = "application/x-rar-compressed";
    DownloadEmployeeDocumentAcceptEnum["applicationXml"] = "application/xml";
    DownloadEmployeeDocumentAcceptEnum["applicationZip"] = "application/zip";
    DownloadEmployeeDocumentAcceptEnum["audioMp4"] = "audio/mp4";
    DownloadEmployeeDocumentAcceptEnum["audioMpeg"] = "audio/mpeg";
    DownloadEmployeeDocumentAcceptEnum["audioWav"] = "audio/wav";
    DownloadEmployeeDocumentAcceptEnum["imageBmp"] = "image/bmp";
    DownloadEmployeeDocumentAcceptEnum["imageGif"] = "image/gif";
    DownloadEmployeeDocumentAcceptEnum["imageHeic"] = "image/heic";
    DownloadEmployeeDocumentAcceptEnum["imageJpeg"] = "image/jpeg";
    DownloadEmployeeDocumentAcceptEnum["imagePng"] = "image/png";
    DownloadEmployeeDocumentAcceptEnum["imageTiff"] = "image/tiff";
    DownloadEmployeeDocumentAcceptEnum["imageWebp"] = "image/webp";
    DownloadEmployeeDocumentAcceptEnum["messageRfc822"] = "message/rfc822";
    DownloadEmployeeDocumentAcceptEnum["textHtml"] = "text/html";
    DownloadEmployeeDocumentAcceptEnum["textRtf"] = "text/rtf";
    DownloadEmployeeDocumentAcceptEnum["videoAvi"] = "video/avi";
    DownloadEmployeeDocumentAcceptEnum["videoMp4"] = "video/mp4";
    DownloadEmployeeDocumentAcceptEnum["videoQuicktime"] = "video/quicktime";
    DownloadEmployeeDocumentAcceptEnum["videoWebm"] = "video/webm";
})(DownloadEmployeeDocumentAcceptEnum || (exports.DownloadEmployeeDocumentAcceptEnum = DownloadEmployeeDocumentAcceptEnum = {}));
/**
 * Download Employee Document
 */
function hrisDownloadEmployeeDocument(client, request, options) {
    return new async_js_1.APIPromise($do(client, request, options));
}
async function $do(client, request, options) {
    const parsed = (0, schemas_js_1.safeParse)(request, (value) => operations.HrisDownloadEmployeeDocumentRequest$outboundSchema.parse(value), "Input validation failed");
    if (!parsed.ok) {
        return [parsed, { status: "invalid" }];
    }
    const payload = parsed.value;
    const body = null;
    const pathParams = {
        id: (0, encodings_js_1.encodeSimple)("id", payload.id, {
            explode: false,
            charEncoding: "percent",
        }),
        subResourceId: (0, encodings_js_1.encodeSimple)("subResourceId", payload.subResourceId, {
            explode: false,
            charEncoding: "percent",
        }),
    };
    const path = (0, url_js_1.pathToFunc)("/unified/hris/employees/{id}/documents/{subResourceId}/download")(pathParams);
    const query = (0, encodings_js_1.encodeFormQuery)({
        "export_format": payload.export_format,
        "format": payload.format,
    });
    const headers = new Headers((0, primitives_js_1.compactMap)({
        Accept: options?.acceptHeaderOverride
            || "application/json;q=1, text/csv;q=0.97, text/plain;q=0.95, application/gzip;q=0.92, application/msword;q=0.89, application/octet-stream;q=0.87, application/pdf;q=0.84, application/rtf;q=0.82, application/vnd.ms-excel;q=0.79, application/vnd.ms-outlook;q=0.76, application/vnd.ms-powerpoint;q=0.74, application/vnd.oasis.opendocument.presentation;q=0.71, application/vnd.oasis.opendocument.spreadsheet;q=0.68, application/vnd.oasis.opendocument.text;q=0.66, application/vnd.openxmlformats-officedocument.presentationml.presentation;q=0.63, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;q=0.61, application/vnd.openxmlformats-officedocument.wordprocessingml.document;q=0.58, application/x-7z-compressed;q=0.55, application/x-rar-compressed;q=0.53, application/xml;q=0.50, application/zip;q=0.47, audio/mp4;q=0.45, audio/mpeg;q=0.42, audio/wav;q=0.39, image/bmp;q=0.37, image/gif;q=0.34, image/heic;q=0.32, image/jpeg;q=0.29, image/png;q=0.26, image/tiff;q=0.24, image/webp;q=0.21, message/rfc822;q=0.18, text/html;q=0.16, text/rtf;q=0.13, video/avi;q=0.11, video/mp4;q=0.08, video/quicktime;q=0.05, video/webm;q=0",
        "x-account-id": (0, encodings_js_1.encodeSimple)("x-account-id", payload["x-account-id"], {
            explode: false,
            charEncoding: "none",
        }),
    }));
    const securityInput = await (0, security_js_1.extractSecurity)(client._options.security);
    const requestSecurity = (0, security_js_1.resolveGlobalSecurity)(securityInput);
    const context = {
        options: client._options,
        baseURL: options?.serverURL ?? client._baseURL ?? "",
        operationID: "hris_download_employee_document",
        oAuth2Scopes: null,
        resolvedSecurity: requestSecurity,
        securitySource: client._options.security,
        retryConfig: options?.retries
            || client._options.retryConfig
            || {
                strategy: "backoff",
                backoff: {
                    initialInterval: 500,
                    maxInterval: 60000,
                    exponent: 1.5,
                    maxElapsedTime: 3600000,
                },
                retryConnectionErrors: true,
            }
            || { strategy: "none" },
        retryCodes: options?.retryCodes || ["429", "408"],
    };
    const requestRes = client._createRequest(context, {
        security: requestSecurity,
        method: "GET",
        baseURL: options?.serverURL,
        path: path,
        headers: headers,
        query: query,
        body: body,
        userAgent: client._options.userAgent,
        timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
    }, options);
    if (!requestRes.ok) {
        return [requestRes, { status: "invalid" }];
    }
    const req = requestRes.value;
    const doResult = await client._do(req, {
        context,
        errorCodes: [
            "400",
            "401",
            "403",
            "404",
            "408",
            "409",
            "412",
            "422",
            "429",
            "4XX",
            "500",
            "501",
            "502",
            "5XX",
        ],
        retryConfig: context.retryConfig,
        retryCodes: context.retryCodes,
    });
    if (!doResult.ok) {
        return [doResult, { status: "request-error", request: req }];
    }
    const response = doResult.value;
    const responseFields = {
        ContentType: response.headers.get("content-type")
            ?? "application/octet-stream",
        StatusCode: response.status,
        RawResponse: response,
        Headers: {},
    };
    const [result] = await M.match(M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/gzip", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/msword", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/pdf", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/rtf", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/vnd.ms-excel", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/vnd.ms-outlook", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/vnd.ms-powerpoint", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/vnd.oasis.opendocument.presentation", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/vnd.oasis.opendocument.spreadsheet", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/vnd.oasis.opendocument.text", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, {
        ctype: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
        key: "Body",
    }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, {
        ctype: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        key: "Body",
    }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, {
        ctype: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        key: "Body",
    }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/x-7z-compressed", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/x-rar-compressed", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/xml", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "application/zip", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "audio/mp4", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "audio/mpeg", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "audio/wav", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/bmp", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/gif", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/heic", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/jpeg", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/png", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/tiff", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "image/webp", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "message/rfc822", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "text/csv", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "text/html", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "text/rtf", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "video/avi", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "video/mp4", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "video/quicktime", key: "Body" }), M.bytes(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, { ctype: "video/webm", key: "Body" }), M.json(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, {
        key: "DownloadApiModel",
    }), M.text(200, operations.HrisDownloadEmployeeDocumentResponse$inboundSchema, {
        key: "DownloadApiModel1",
    }), M.jsonErr(400, errors.BadRequestResponse$inboundSchema), M.jsonErr(401, errors.UnauthorizedResponse$inboundSchema), M.jsonErr(403, errors.ForbiddenResponse$inboundSchema), M.jsonErr(404, errors.NotFoundResponse$inboundSchema), M.jsonErr(408, errors.RequestTimedOutResponse$inboundSchema, {
        hdrs: true,
    }), M.jsonErr(409, errors.ConflictResponse$inboundSchema), M.jsonErr(412, errors.PreconditionFailedResponse$inboundSchema), M.jsonErr(422, errors.UnprocessableEntityResponse$inboundSchema), M.jsonErr(429, errors.TooManyRequestsResponse$inboundSchema), M.jsonErr(500, errors.InternalServerErrorResponse$inboundSchema), M.jsonErr(501, errors.NotImplementedResponse$inboundSchema), M.jsonErr(502, errors.BadGatewayResponse$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
    if (!result.ok) {
        return [result, { status: "complete", request: req, response }];
    }
    return [result, { status: "complete", request: req, response }];
}
//# sourceMappingURL=hrisDownloadEmployeeDocument.js.map