var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _HttpRuntime_instances, _HttpRuntime_request;
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import "../_dnt.polyfills.js";
import * as t from "../types.js";
import { runtimes } from "../wit.js";
import { Runtime } from "./mod.js";
import { fx } from "../index.js";
export class HttpRuntime extends Runtime {
    constructor(endpoint, certSecret, basicAuthSecret) {
        super(runtimes.registerHttpRuntime({
            endpoint,
            certSecret,
            basicAuthSecret,
        }));
        _HttpRuntime_instances.add(this);
        Object.defineProperty(this, "endpoint", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: endpoint
        });
        Object.defineProperty(this, "certSecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: certSecret
        });
        Object.defineProperty(this, "basicAuthSecret", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: basicAuthSecret
        });
    }
    get(inp, out, options) {
        return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "get", inp, out, options, fx.read());
    }
    post(inp, out, options, effect) {
        return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "post", inp, out, options, effect ?? fx.create());
    }
    put(inp, out, options, effect) {
        return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "put", inp, out, options, effect ?? fx.update());
    }
    patch(inp, out, options, effect) {
        return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "patch", inp, out, options, effect ?? fx.update());
    }
    delete_(inp, out, options, effect) {
        return __classPrivateFieldGet(this, _HttpRuntime_instances, "m", _HttpRuntime_request).call(this, "delete", inp, out, options, effect ?? fx.delete_());
    }
}
_HttpRuntime_instances = new WeakSet(), _HttpRuntime_request = function _HttpRuntime_request(method, inp, out, options, effect) {
    const matId = runtimes.httpRequest({
        runtime: this._id,
        effect,
    }, { method, ...options });
    const mat = {
        _id: matId,
        method,
        ...options,
    };
    return t.func(inp, out, mat);
};
