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 _a, _Policy_serializeContext;
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import "./_dnt.polyfills.js";
import { core } from "./wit.js";
export class PolicyPerEffectObject {
    constructor(value) {
        Object.defineProperty(this, "value", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: value
        });
    }
}
export default class Policy {
    constructor(_id, name) {
        Object.defineProperty(this, "_id", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: _id
        });
        Object.defineProperty(this, "name", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: name
        });
    }
    static public() {
        const [id, name] = core.getPublicPolicy();
        return new Policy(id, name);
    }
    static context(key, check) {
        const [id, name] = core.registerContextPolicy(key, __classPrivateFieldGet(Policy, _a, "m", _Policy_serializeContext).call(Policy, check ?? null));
        return new Policy(id, name);
    }
    static internal() {
        const [id, name] = core.getInternalPolicy();
        return new Policy(id, name);
    }
    static create(name, materializerId) {
        return new Policy(core.registerPolicy({ name, materializer: materializerId }), name);
    }
    /** create policy based on effects */
    static on(effects) {
        return new PolicyPerEffectObject(effects);
    }
}
_a = Policy, _Policy_serializeContext = function _Policy_serializeContext(check) {
    if (check === null) {
        return { tag: "not-null" };
    }
    if (typeof check === "string") {
        return { tag: "value", val: check };
    }
    if (!(check instanceof RegExp)) {
        throw new Error("Invalid context check: expected null, string, or RegExp");
    }
    return { tag: "pattern", val: check.source };
};
