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 _SubstantialRuntime_instances, _SubstantialRuntime_internalLinkParentChild;
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import "../_dnt.polyfills.js";
import { Runtime } from "./mod.js";
import { runtimes } from "../wit.js";
import { Func } from "../types.js";
export class SubstantialRuntime extends Runtime {
    constructor(backend, fileDescriptions) {
        const id = runtimes.registerSubstantialRuntime({
            backend,
            fileDescriptions,
        });
        super(id);
        _SubstantialRuntime_instances.add(this);
        Object.defineProperty(this, "backend", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        this.backend = backend;
    }
    _genericSubstantialFunc(data) {
        const funcData = runtimes.generateSubstantialOperation(this._id, data);
        return Func.fromTypeFunc(funcData);
    }
    start(kwargs, { secrets } = {}) {
        return this._genericSubstantialFunc({
            tag: "start",
            val: { secrets: secrets ?? [], funcArg: kwargs._id },
        });
    }
    startRaw({ secrets } = {}) {
        return this._genericSubstantialFunc({
            tag: "start-raw",
            val: { secrets: secrets ?? [] },
        });
    }
    stop() {
        return this._genericSubstantialFunc({
            tag: "stop",
        });
    }
    send(payload) {
        return this._genericSubstantialFunc({
            tag: "send",
            val: payload._id,
        });
    }
    sendRaw() {
        return this._genericSubstantialFunc({
            tag: "send-raw",
        });
    }
    queryResources() {
        return this._genericSubstantialFunc({
            tag: "resources",
        });
    }
    queryResults(output) {
        return this._genericSubstantialFunc({
            tag: "results",
            val: output._id,
        });
    }
    queryResultsRaw() {
        return this._genericSubstantialFunc({
            tag: "results-raw",
        });
    }
    advancedFilters() {
        return this._genericSubstantialFunc({
            tag: "advanced-filters"
        });
    }
    internals() {
        return {
            _sub_internal_start: this.startRaw(),
            _sub_internal_stop: this.stop(),
            _sub_internal_send: this.sendRaw(),
            _sub_internal_results: this.queryResultsRaw(),
            _sub_internal_link_parent_child: __classPrivateFieldGet(this, _SubstantialRuntime_instances, "m", _SubstantialRuntime_internalLinkParentChild).call(this),
        };
    }
}
_SubstantialRuntime_instances = new WeakSet(), _SubstantialRuntime_internalLinkParentChild = function _SubstantialRuntime_internalLinkParentChild() {
    return this._genericSubstantialFunc({
        tag: "internal-link-parent-child",
    });
};
export class Backend {
    static devMemory() {
        return { tag: "memory" };
    }
    static devFs() {
        return { tag: "fs" };
    }
    static redis(connectionStringSecret) {
        return {
            tag: "redis",
            val: {
                connectionStringSecret,
            },
        };
    }
}
export class WorkflowFile {
    constructor(file, kind, deps = []) {
        Object.defineProperty(this, "file", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: file
        });
        Object.defineProperty(this, "kind", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: kind
        });
        Object.defineProperty(this, "deps", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: deps
        });
        Object.defineProperty(this, "workflows", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: []
        });
    }
    static deno(file, deps = []) {
        return new WorkflowFile(file, "deno", deps);
    }
    static python(file, deps = []) {
        return new WorkflowFile(file, "python", deps);
    }
    import(names) {
        this.workflows.push(...names);
        return this;
    }
    build() {
        return {
            deps: this.deps,
            file: this.file,
            kind: this.kind,
            workflows: this.workflows,
        };
    }
}
