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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _Config_instances, _Config_factory, _Config_name, _Config_owner, _Config_provides, _Config_useQueries, _Config_version, _Config_assets, _Config_webviewAssets, _Config_newActorSpec;
import { Definition } from '@devvit/protos/lib/Types.js';
import { ActorSpec, DependencySpec, PackageQuery, PackageSpec, } from '@devvit/protos/types/devvit/runtime/bundle.js';
import { PLUGIN_NAME, resolveActorHostname } from '@devvit/shared-types/HostnameUtil.js';
import { NonNull } from '@devvit/shared-types/NonNull.js';
export class Config {
    get assets() {
        return __classPrivateFieldGet(this, _Config_assets, "f");
    }
    get webviewAssets() {
        return __classPrivateFieldGet(this, _Config_webviewAssets, "f");
    }
    get providedDefinitions() {
        return __classPrivateFieldGet(this, _Config_provides, "f");
    }
    constructor(factory, actorSpec, assets, webviewAssets) {
        _Config_instances.add(this);
        _Config_factory.set(this, void 0);
        _Config_name.set(this, void 0);
        _Config_owner.set(this, void 0);
        _Config_provides.set(this, []);
        _Config_useQueries.set(this, []);
        _Config_version.set(this, void 0);
        _Config_assets.set(this, void 0);
        _Config_webviewAssets.set(this, void 0);
        __classPrivateFieldSet(this, _Config_factory, factory, "f");
        __classPrivateFieldSet(this, _Config_name, actorSpec.name, "f");
        __classPrivateFieldSet(this, _Config_owner, actorSpec.owner, "f");
        __classPrivateFieldSet(this, _Config_version, actorSpec.version, "f");
        __classPrivateFieldSet(this, _Config_assets, Object.freeze(assets), "f");
        __classPrivateFieldSet(this, _Config_webviewAssets, Object.freeze(webviewAssets), "f");
    }
    export(namespace) {
        return DependencySpec.fromPartial({
            actor: __classPrivateFieldGet(this, _Config_instances, "m", _Config_newActorSpec).call(this),
            hostname: resolveActorHostname(NonNull(__classPrivateFieldGet(this, _Config_name, "f")), namespace),
            provides: __classPrivateFieldGet(this, _Config_provides, "f").map((definition) => {
                return PackageSpec.fromPartial({
                    actor: __classPrivateFieldGet(this, _Config_instances, "m", _Config_newActorSpec).call(this),
                    definition: Definition.toSerializable(definition),
                });
            }),
            uses: __classPrivateFieldGet(this, _Config_useQueries, "f"),
        });
    }
    provides(definition) {
        __classPrivateFieldGet(this, _Config_provides, "f").push(definition);
    }
    use(definition, options = {}) {
        const query = PackageQuery.fromPartial({
            ...options,
            name: options.name ?? PLUGIN_NAME,
            owner: options.owner,
            versions: options.versions,
            typeName: definition.fullName,
        });
        __classPrivateFieldGet(this, _Config_useQueries, "f").push(query);
        return __classPrivateFieldGet(this, _Config_factory, "f").Build(definition, query);
    }
    uses(definition) {
        return __classPrivateFieldGet(this, _Config_useQueries, "f").some((query) => query.typeName === definition.fullName);
    }
}
_Config_factory = new WeakMap(), _Config_name = new WeakMap(), _Config_owner = new WeakMap(), _Config_provides = new WeakMap(), _Config_useQueries = new WeakMap(), _Config_version = new WeakMap(), _Config_assets = new WeakMap(), _Config_webviewAssets = new WeakMap(), _Config_instances = new WeakSet(), _Config_newActorSpec = function _Config_newActorSpec() {
    return ActorSpec.fromPartial({
        name: __classPrivateFieldGet(this, _Config_name, "f") ?? '',
        owner: __classPrivateFieldGet(this, _Config_owner, "f") ?? '',
        version: __classPrivateFieldGet(this, _Config_version, "f") ?? '',
    });
};
