'use strict';

function createServiceRef(options) {
  const { id, scope = "plugin", multiton = false, defaultFactory } = options;
  return {
    id,
    scope,
    multiton,
    get T() {
      throw new Error(`tried to read ServiceRef.T of ${this}`);
    },
    toString() {
      return `serviceRef{${options.id}}`;
    },
    toJSON() {
      return {
        $$type: "@backstage/ServiceRef",
        id,
        scope,
        multiton
      };
    },
    $$type: "@backstage/ServiceRef",
    __defaultFactory: defaultFactory
  };
}
function createServiceFactory(options) {
  if (options.service.scope === "root") {
    const c2 = options;
    return {
      $$type: "@backstage/BackendFeature",
      version: "v1",
      featureType: "service",
      service: c2.service,
      initialization: c2.initialization,
      deps: options.deps,
      factory: async (deps) => c2.factory(deps)
    };
  }
  const c = options;
  return {
    $$type: "@backstage/BackendFeature",
    version: "v1",
    featureType: "service",
    service: c.service,
    initialization: c.initialization,
    ..."createRootContext" in options ? {
      createRootContext: async (deps) => c?.createRootContext?.(deps)
    } : {},
    deps: options.deps,
    factory: async (deps, ctx) => c.factory(deps, ctx)
  };
}

exports.createServiceFactory = createServiceFactory;
exports.createServiceRef = createServiceRef;
//# sourceMappingURL=types.cjs.js.map
