"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "DefaultHttpClientBuilder", {
    enumerable: true,
    get: function() {
        return DefaultHttpClientBuilder;
    }
});
const _serversettingsconstants = require("../constants/server-settings.constants");
const _axios = /*#__PURE__*/ _interop_require_default(require("axios"));
const _octoprintserviceconstants = require("../services/octoprint/constants/octoprint-service.constants");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
class DefaultHttpClientBuilder {
    axiosOptions;
    constructor(){
        this.axiosOptions = {
            baseURL: "",
            timeout: (0, _serversettingsconstants.getDefaultTimeout)().apiTimeout,
            headers: {
                [_octoprintserviceconstants.contentTypeHeaderKey]: _octoprintserviceconstants.jsonContentType
            }
        };
    }
    build() {
        const axiosConfig = {
            baseURL: this.axiosOptions.baseURL,
            timeout: this.axiosOptions.timeout,
            headers: this.axiosOptions.headers,
            data: this.axiosOptions.data,
            maxBodyLength: this.axiosOptions.maxBodyLength ?? 1000 * 1000 * 1000,
            maxContentLength: this.axiosOptions.maxContentLength ?? 1000 * 1000 * 1000,
            responseType: this.axiosOptions.responseType,
            onUploadProgress: this.axiosOptions.onUploadProgress
        };
        return _axios.default.create(axiosConfig);
    }
    withMaxBodyLength(maxBodyLength) {
        this.axiosOptions.maxBodyLength = maxBodyLength;
        return this;
    }
    withMaxContentLength(maxContentLength) {
        this.axiosOptions.maxContentLength = maxContentLength;
        return this;
    }
    withBaseUrl(baseUrl) {
        if (!baseUrl?.length) {
            throw new Error("Base address may not be an empty string");
        }
        this.axiosOptions.baseURL = baseUrl;
        return this;
    }
    withTimeout(timeout) {
        if (!timeout || timeout <= 0) {
            throw new Error("Timeout value (milliseconds) must be greater than 0");
        }
        this.axiosOptions.timeout = timeout;
        return this;
    }
    withMultiPartFormData() {
        this.withHeaders({
            "Content-Type": _octoprintserviceconstants.multiPartContentType
        });
        return this;
    }
    withStreamResponse() {
        this.axiosOptions.responseType = "stream";
        return this;
    }
    withOnUploadProgress(handler) {
        this.axiosOptions.onUploadProgress = handler;
        return this;
    }
    withJsonContentTypeHeader() {
        this.withHeaders({
            [_octoprintserviceconstants.contentTypeHeaderKey]: _octoprintserviceconstants.jsonContentType
        });
        return this;
    }
    withHeaders(headers) {
        this.axiosOptions.headers = {
            ...this.axiosOptions.headers,
            ...headers
        };
        return this;
    }
}

//# sourceMappingURL=default-http-client.builder.js.map