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 _KvRuntime_instances, _KvRuntime_operation;
// 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 * as t from "../types.js";
import { runtimes } from "../wit.js";
import { fx } from "../index.js";
class KvOperationMat {
    constructor(id, operation) {
        Object.defineProperty(this, "operation", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "_id", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        this._id = id;
        this.operation = operation;
    }
}
export class KvRuntime extends Runtime {
    constructor(url) {
        const id = runtimes.registerKvRuntime({ url });
        super(id);
        _KvRuntime_instances.add(this);
        Object.defineProperty(this, "url", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        this.url = url;
    }
    set() {
        const mat = __classPrivateFieldGet(this, _KvRuntime_instances, "m", _KvRuntime_operation).call(this, "set", fx.update());
        return t.func(t.struct({ "key": t.string(), "value": t.string() }), t.string(), mat);
    }
    get() {
        const mat = __classPrivateFieldGet(this, _KvRuntime_instances, "m", _KvRuntime_operation).call(this, "get", fx.read());
        // FIXME: consolidate response type construction inside tg_core
        return t.func(t.struct({ "key": t.string() }), t.string().optional(), mat);
    }
    delete() {
        const mat = __classPrivateFieldGet(this, _KvRuntime_instances, "m", _KvRuntime_operation).call(this, "delete", fx.delete_());
        return t.func(t.struct({ "key": t.string() }), t.integer(), mat);
    }
    keys() {
        const mat = __classPrivateFieldGet(this, _KvRuntime_instances, "m", _KvRuntime_operation).call(this, "keys", fx.read());
        return t.func(t.struct({ "filter": t.string().optional() }), t.list(t.string()), mat);
    }
    values() {
        const mat = __classPrivateFieldGet(this, _KvRuntime_instances, "m", _KvRuntime_operation).call(this, "values", fx.read());
        return t.func(t.struct({ "filter": t.string().optional() }), t.list(t.string()), mat);
    }
}
_KvRuntime_instances = new WeakSet(), _KvRuntime_operation = function _KvRuntime_operation(operation, effect) {
    const mad_id = runtimes.kvOperation({
        runtime: this._id,
        effect: effect,
    }, operation);
    return new KvOperationMat(mad_id, operation);
};
