/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var blueprint_service_exports = {};
__export(blueprint_service_exports, {
  FlowSurfaceApprovalBlueprintService: () => FlowSurfaceApprovalBlueprintService
});
module.exports = __toCommonJS(blueprint_service_exports);
var import_data_source_manager = require("@nocobase/data-source-manager");
var import_utils = require("@nocobase/utils");
var import_lodash = __toESM(require("lodash"));
var import_service_utils = require("../service-utils");
var import_errors = require("../errors");
var import_blueprint = require("./blueprint");
var import_authoring_validation = require("./authoring-validation");
var import_builder = require("./builder");
class FlowSurfaceApprovalBlueprintService {
  constructor(deps) {
    this.deps = deps;
  }
  parseApprovalBlueprintCollection(collectionValue) {
    const normalizedCollection = String(collectionValue || "").trim();
    if (!normalizedCollection) {
      (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint requires an approval workflow collection binding`);
    }
    let [dataSourceKey, collectionName] = (0, import_data_source_manager.parseCollectionName)(normalizedCollection);
    if (!normalizedCollection.includes(":") && normalizedCollection.includes(".") && collectionName === normalizedCollection) {
      const [candidateDataSourceKey, ...candidateCollectionParts] = normalizedCollection.split(".");
      const candidateCollectionName = candidateCollectionParts.join(".");
      if (candidateDataSourceKey && candidateCollectionName && this.deps.hasDataSource(candidateDataSourceKey)) {
        dataSourceKey = candidateDataSourceKey;
        collectionName = candidateCollectionName;
      }
    }
    if (!collectionName) {
      (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint collection '${normalizedCollection}' is invalid`);
    }
    return {
      dataSourceKey: dataSourceKey || "main",
      collectionName
    };
  }
  async resolveApprovalBlueprintBindingContext(document, transaction) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
    if (!import_lodash.default.isUndefined(document.workflowId)) {
      const workflow2 = await this.deps.db.getRepository("workflows").findOne({
        filterByTk: document.workflowId,
        transaction
      });
      if (!workflow2) {
        (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint workflow '${document.workflowId}' not found`);
      }
      if ((((_a = workflow2.get) == null ? void 0 : _a.call(workflow2, "type")) || workflow2.type) !== "approval") {
        (0, import_errors.throwBadRequest)(
          `flowSurfaces applyApprovalBlueprint workflow '${document.workflowId}' must be an approval workflow`
        );
      }
      const workflowConfig2 = import_lodash.default.cloneDeep(((_b = workflow2.get) == null ? void 0 : _b.call(workflow2, "config")) || workflow2.config || {});
      const collection2 = this.parseApprovalBlueprintCollection(workflowConfig2.collection);
      return {
        surface: document.surface,
        ...collection2,
        bindingResource: "workflows",
        filterByTk: ((_c = workflow2.get) == null ? void 0 : _c.call(workflow2, "id")) || workflow2.id || document.workflowId,
        rootUse: document.surface === "initiator" ? "TriggerChildPageModel" : "ApplyTaskCardDetailsModel",
        rootUidKey: document.surface === "initiator" ? "approvalUid" : "taskCardUid",
        existingUid: String(
          document.surface === "initiator" ? workflowConfig2.approvalUid || "" : workflowConfig2.taskCardUid || ""
        ).trim() || void 0,
        workflowId: ((_d = workflow2.get) == null ? void 0 : _d.call(workflow2, "id")) || workflow2.id || document.workflowId,
        workflow: workflow2
      };
    }
    const node = await this.deps.db.getRepository("flow_nodes").findOne({
      filterByTk: document.nodeId,
      appends: ["workflow"],
      transaction
    });
    if (!node) {
      (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint node '${document.nodeId}' not found`);
    }
    if ((((_e = node.get) == null ? void 0 : _e.call(node, "type")) || node.type) !== "approval") {
      (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint node '${document.nodeId}' must be an approval node`);
    }
    const workflow = ((_f = node.get) == null ? void 0 : _f.call(node, "workflow")) || node.workflow;
    if (!workflow) {
      (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint node '${document.nodeId}' is missing its workflow relation`);
    }
    const resolvedNodeId = ((_g = node.get) == null ? void 0 : _g.call(node, "id")) || node.id || document.nodeId;
    if (import_lodash.default.isNil(resolvedNodeId)) {
      (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint node id could not be resolved`);
    }
    const workflowConfig = import_lodash.default.cloneDeep(((_h = workflow.get) == null ? void 0 : _h.call(workflow, "config")) || workflow.config || {});
    const nodeConfig = import_lodash.default.cloneDeep(((_i = node.get) == null ? void 0 : _i.call(node, "config")) || node.config || {});
    const collection = this.parseApprovalBlueprintCollection(workflowConfig.collection);
    return {
      surface: document.surface,
      ...collection,
      bindingResource: "flow_nodes",
      filterByTk: resolvedNodeId,
      rootUse: document.surface === "approver" ? "ApprovalChildPageModel" : "ApprovalTaskCardDetailsModel",
      rootUidKey: document.surface === "approver" ? "approvalUid" : "taskCardUid",
      existingUid: String(document.surface === "approver" ? nodeConfig.approvalUid || "" : nodeConfig.taskCardUid || "").trim() || void 0,
      workflowId: ((_j = workflow.get) == null ? void 0 : _j.call(workflow, "id")) || workflow.id,
      nodeId: resolvedNodeId,
      workflow,
      node
    };
  }
  buildApprovalBlueprintSurfaceRootTree(context) {
    switch (context.rootUse) {
      case "TriggerChildPageModel":
        return (0, import_builder.buildApprovalInitiatorSurfaceTree)({
          dataSourceKey: context.dataSourceKey,
          collectionName: context.collectionName
        });
      case "ApprovalChildPageModel":
        return (0, import_builder.buildApprovalApproverSurfaceTree)({
          dataSourceKey: context.dataSourceKey,
          collectionName: context.collectionName
        });
      case "ApplyTaskCardDetailsModel":
        return (0, import_builder.buildApprovalTaskCardSurfaceTree)({
          detailsUse: "ApplyTaskCardDetailsModel",
          gridUse: "ApplyTaskCardGridModel",
          dataSourceKey: context.dataSourceKey,
          collectionName: context.collectionName
        });
      case "ApprovalTaskCardDetailsModel":
        return (0, import_builder.buildApprovalTaskCardSurfaceTree)({
          detailsUse: "ApprovalTaskCardDetailsModel",
          gridUse: "ApprovalTaskCardGridModel",
          dataSourceKey: context.dataSourceKey,
          collectionName: context.collectionName
        });
      default: {
        const unsupportedUse = context.rootUse;
        (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint unsupported root use '${unsupportedUse}'`);
      }
    }
  }
  buildApprovalBlueprintPageSurfaceRootTree(context) {
    if (context.rootUse === "TriggerChildPageModel") {
      return (0, import_builder.buildApprovalInitiatorSurfaceTree)({
        dataSourceKey: context.dataSourceKey,
        collectionName: context.collectionName
      });
    }
    if (context.rootUse === "ApprovalChildPageModel") {
      return (0, import_builder.buildApprovalApproverSurfaceTree)({
        dataSourceKey: context.dataSourceKey,
        collectionName: context.collectionName
      });
    }
    (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint root use '${context.rootUse}' does not support tabs`);
  }
  getApprovalBlueprintExpectedTabUse(context) {
    return context.rootUse === "TriggerChildPageModel" ? "TriggerChildPageTabModel" : "ApprovalChildPageTabModel";
  }
  getApprovalBlueprintExpectedGridUse(context) {
    switch (context.rootUse) {
      case "TriggerChildPageModel":
        return "TriggerBlockGridModel";
      case "ApprovalChildPageModel":
        return "ApprovalBlockGridModel";
      case "ApplyTaskCardDetailsModel":
        return "ApplyTaskCardGridModel";
      case "ApprovalTaskCardDetailsModel":
        return "ApprovalTaskCardGridModel";
      default: {
        const unsupportedUse = context.rootUse;
        (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint unsupported root use '${unsupportedUse}'`);
      }
    }
  }
  async findApprovalBlueprintSurfaceRoot(context, transaction) {
    if (!context.existingUid) {
      return null;
    }
    const root = await this.deps.repository.findModelById(context.existingUid, {
      transaction,
      includeAsyncNode: true
    });
    if (!(root == null ? void 0 : root.uid) || root.use !== context.rootUse) {
      return null;
    }
    return root;
  }
  async createApprovalBlueprintSurfaceRoot(context, transaction) {
    const tree = this.buildApprovalBlueprintSurfaceRootTree(context);
    this.deps.contractGuard.validateNodeTreeAgainstContract(tree);
    const root = await this.deps.repository.insertModel(tree, {
      transaction
    });
    const grid = await this.deps.surfaceContext.resolveGridNode(root.uid, transaction);
    return {
      root,
      rootUid: root.uid,
      gridUid: grid.uid
    };
  }
  async ensureApprovalBlueprintPageSurfaceStructure(root, context, transaction) {
    var _a, _b, _c, _d, _e;
    const expectedTabUse = this.getApprovalBlueprintExpectedTabUse(context);
    let tab = import_lodash.default.castArray(((_a = root == null ? void 0 : root.subModels) == null ? void 0 : _a.tabs) || []).find((item) => (item == null ? void 0 : item.uid) && (item == null ? void 0 : item.use) === expectedTabUse) || import_lodash.default.castArray(((_b = root == null ? void 0 : root.subModels) == null ? void 0 : _b.tabs) || [])[0];
    if (!(tab == null ? void 0 : tab.uid)) {
      const defaultTree = this.buildApprovalBlueprintPageSurfaceRootTree(context);
      const defaultTab = import_lodash.default.castArray(((_c = defaultTree == null ? void 0 : defaultTree.subModels) == null ? void 0 : _c.tabs) || [])[0];
      await this.deps.repository.upsertModel(
        {
          parentId: root.uid,
          subKey: "tabs",
          subType: "array",
          ...defaultTab
        },
        { transaction }
      );
      tab = await this.deps.repository.findModelById(defaultTab.uid, {
        transaction,
        includeAsyncNode: true
      });
    } else if (tab.use !== expectedTabUse) {
      await this.deps.repository.patch(
        {
          uid: tab.uid,
          use: expectedTabUse
        },
        { transaction }
      );
      tab = await this.deps.repository.findModelById(tab.uid, {
        transaction,
        includeAsyncNode: true
      });
    }
    for (const extraTab of import_lodash.default.castArray(((_d = root == null ? void 0 : root.subModels) == null ? void 0 : _d.tabs) || []).filter(
      (item) => (item == null ? void 0 : item.uid) && item.uid !== tab.uid
    )) {
      await this.deps.removeNodeTreeWithBindings(extraTab.uid, transaction);
    }
    const expectedGridUse = this.getApprovalBlueprintExpectedGridUse(context);
    const grid = ((_e = tab == null ? void 0 : tab.subModels) == null ? void 0 : _e.grid) || ((tab == null ? void 0 : tab.uid) ? await this.deps.repository.findModelByParentId(tab.uid, {
      transaction,
      subKey: "grid",
      includeAsyncNode: true
    }) : null);
    if (!(grid == null ? void 0 : grid.uid)) {
      const gridUid = (0, import_utils.uid)();
      await this.deps.repository.upsertModel(
        {
          uid: gridUid,
          parentId: tab.uid,
          subKey: "grid",
          subType: "object",
          async: true,
          use: expectedGridUse
        },
        { transaction }
      );
      return gridUid;
    }
    if (grid.use !== expectedGridUse) {
      await this.deps.repository.patch(
        {
          uid: grid.uid,
          use: expectedGridUse
        },
        { transaction }
      );
    }
    return grid.uid;
  }
  async ensureApprovalBlueprintTaskCardSurfaceStructure(root, context, transaction) {
    var _a;
    const expectedGridUse = this.getApprovalBlueprintExpectedGridUse(context);
    const grid = ((_a = root == null ? void 0 : root.subModels) == null ? void 0 : _a.grid) || await this.deps.repository.findModelByParentId(root.uid, {
      transaction,
      subKey: "grid",
      includeAsyncNode: true
    });
    if (!(grid == null ? void 0 : grid.uid)) {
      const gridUid = (0, import_utils.uid)();
      await this.deps.repository.upsertModel(
        {
          uid: gridUid,
          parentId: root.uid,
          subKey: "grid",
          subType: "object",
          use: expectedGridUse
        },
        { transaction }
      );
      return gridUid;
    }
    if (grid.use !== expectedGridUse) {
      await this.deps.repository.patch(
        {
          uid: grid.uid,
          use: expectedGridUse
        },
        { transaction }
      );
    }
    return grid.uid;
  }
  async syncApprovalBlueprintSurfaceAsyncShape(surfaceRoot, context, transaction) {
    await this.deps.setNodeAsyncFlag(surfaceRoot.rootUid, true, transaction);
    if (context.surface === "taskCard") {
      return;
    }
    await this.deps.setNodeAsyncFlag(surfaceRoot.gridUid, true, transaction);
  }
  async syncApprovalBlueprintSurfaceRoot(rootUid, context, transaction) {
    const root = await this.deps.repository.findModelById(rootUid, {
      transaction,
      includeAsyncNode: true
    });
    if (!(root == null ? void 0 : root.uid)) {
      return;
    }
    const stepParams = import_lodash.default.cloneDeep(root.stepParams || {});
    const nextInit = {
      dataSourceKey: context.dataSourceKey,
      collectionName: context.collectionName
    };
    if (context.rootUse === "TriggerChildPageModel") {
      const currentInit2 = import_lodash.default.get(stepParams, ["TriggerChildPageSettings", "init"]) || {};
      if (import_lodash.default.isEqual(currentInit2, nextInit)) {
        return;
      }
      import_lodash.default.set(stepParams, ["TriggerChildPageSettings", "init"], nextInit);
      await this.deps.repository.patch(
        {
          uid: rootUid,
          stepParams
        },
        { transaction }
      );
      return;
    }
    if (context.rootUse === "ApprovalChildPageModel") {
      const currentInit2 = import_lodash.default.get(stepParams, ["ApprovalChildPageSettings", "init"]) || {};
      const currentResourceInit = import_lodash.default.get(stepParams, ["resourceSettings", "init"]) || {};
      if (import_lodash.default.isEqual(currentInit2, nextInit) && import_lodash.default.isEqual(currentResourceInit, nextInit)) {
        return;
      }
      import_lodash.default.set(stepParams, ["ApprovalChildPageSettings", "init"], nextInit);
      import_lodash.default.set(stepParams, ["resourceSettings", "init"], nextInit);
      await this.deps.repository.patch(
        {
          uid: rootUid,
          stepParams
        },
        { transaction }
      );
      return;
    }
    const currentInit = import_lodash.default.get(stepParams, ["resourceSettings", "init"]) || {};
    if (!import_lodash.default.isEqual(currentInit, nextInit)) {
      import_lodash.default.set(stepParams, ["resourceSettings", "init"], nextInit);
    }
    if (!import_lodash.default.get(stepParams, ["detailsSettings", "layout", "layout"])) {
      import_lodash.default.set(stepParams, ["detailsSettings", "layout", "layout"], "horizontal");
    }
    if (import_lodash.default.isEqual(stepParams, root.stepParams || {})) {
      return;
    }
    await this.deps.repository.patch(
      {
        uid: rootUid,
        stepParams
      },
      { transaction }
    );
  }
  async ensureApprovalBlueprintSurfaceRoot(context, transaction) {
    const existingRoot = await this.findApprovalBlueprintSurfaceRoot(context, transaction);
    if (!(existingRoot == null ? void 0 : existingRoot.uid)) {
      return this.createApprovalBlueprintSurfaceRoot(context, transaction);
    }
    const gridUid = context.surface === "taskCard" ? await this.ensureApprovalBlueprintTaskCardSurfaceStructure(existingRoot, context, transaction) : await this.ensureApprovalBlueprintPageSurfaceStructure(existingRoot, context, transaction);
    await this.syncApprovalBlueprintSurfaceAsyncShape(
      {
        root: existingRoot,
        rootUid: existingRoot.uid,
        gridUid
      },
      context,
      transaction
    );
    await this.syncApprovalBlueprintSurfaceRoot(existingRoot.uid, context, transaction);
    const root = await this.deps.repository.findModelById(existingRoot.uid, {
      transaction,
      includeAsyncNode: true
    });
    return {
      root,
      rootUid: root.uid,
      gridUid
    };
  }
  async persistApprovalBlueprintBinding(context, rootUid, transaction) {
    var _a;
    const configSource = context.bindingResource === "workflows" ? context.workflow : context.node;
    const currentConfig = import_lodash.default.cloneDeep(((_a = configSource == null ? void 0 : configSource.get) == null ? void 0 : _a.call(configSource, "config")) || (configSource == null ? void 0 : configSource.config) || {});
    if ((currentConfig == null ? void 0 : currentConfig[context.rootUidKey]) === rootUid) {
      return;
    }
    await this.deps.db.getRepository(context.bindingResource).update({
      filterByTk: context.filterByTk,
      values: {
        config: {
          ...currentConfig,
          [context.rootUidKey]: rootUid
        }
      },
      transaction
    });
  }
  async applyApprovalBlueprintPageSurface(document, surfaceRoot, options) {
    await this.deps.compose(
      {
        target: {
          uid: surfaceRoot.gridUid
        },
        mode: "replace",
        blocks: document.blocks || [],
        layout: document.layout
      },
      options
    );
  }
  async applyApprovalBlueprintTaskCardSurface(document, surfaceRoot, context, options) {
    var _a, _b;
    const normalizedFields = import_lodash.default.castArray(document.fields || []).map(
      (item, index) => (0, import_service_utils.normalizeComposeFieldSpec)(item, index)
    );
    normalizedFields.forEach((field) => {
      if (field.target) {
        (0, import_errors.throwBadRequest)(`flowSurfaces applyApprovalBlueprint taskCard fields do not support target`);
      }
    });
    (0, import_service_utils.assertFlowSurfaceComposeUniqueKeys)(normalizedFields, "flowSurfaces applyApprovalBlueprint taskCard fields");
    const initialGrid = await this.deps.repository.findModelById(surfaceRoot.gridUid, {
      transaction: options.transaction,
      includeAsyncNode: true
    });
    for (const item of import_lodash.default.castArray(((_a = initialGrid == null ? void 0 : initialGrid.subModels) == null ? void 0 : _a.items) || []).filter((candidate) => candidate == null ? void 0 : candidate.uid)) {
      await this.deps.removeNodeTreeWithBindings(item.uid, options.transaction);
    }
    const createdByKey = {};
    for (const fieldSpec of normalizedFields) {
      let result;
      try {
        result = await this.deps.addField(
          {
            target: {
              uid: surfaceRoot.rootUid
            },
            ...fieldSpec.key ? { key: fieldSpec.key } : {},
            dataSourceKey: context.dataSourceKey,
            collectionName: context.collectionName,
            ...fieldSpec.fieldPath ? { fieldPath: fieldSpec.fieldPath } : {},
            ...fieldSpec.associationPathName ? { associationPathName: fieldSpec.associationPathName } : {},
            ...fieldSpec.renderer ? { renderer: fieldSpec.renderer } : {},
            ...fieldSpec.type ? { type: fieldSpec.type } : {},
            ...fieldSpec.popup ? { popup: fieldSpec.popup } : {},
            ...Object.keys(fieldSpec.settings || {}).length ? { settings: fieldSpec.settings } : {}
          },
          options
        );
      } catch (error) {
        if ((0, import_errors.isFlowSurfaceError)(error)) {
          throw error;
        }
        const message = error instanceof Error ? error.message : String(error);
        (0, import_errors.throwInternalError)(
          `flowSurfaces applyApprovalBlueprint taskCard addField '${fieldSpec.key}' failed: ${message}`
        );
      }
      createdByKey[fieldSpec.key] = {
        uid: result.wrapperUid || result.uid
      };
    }
    const finalGrid = await this.deps.repository.findModelById(surfaceRoot.gridUid, {
      transaction: options.transaction,
      includeAsyncNode: true
    });
    const layoutPayload = this.deps.buildComposeLayoutPayload({
      layout: document.layout,
      createdByKey,
      finalItems: import_lodash.default.castArray(((_b = finalGrid == null ? void 0 : finalGrid.subModels) == null ? void 0 : _b.items) || []).filter((item) => item == null ? void 0 : item.uid)
    });
    try {
      await this.deps.setLayout(
        {
          target: {
            uid: surfaceRoot.gridUid
          },
          ...layoutPayload
        },
        options
      );
    } catch (error) {
      if ((0, import_errors.isFlowSurfaceError)(error)) {
        throw error;
      }
      const message = error instanceof Error ? error.message : String(error);
      (0, import_errors.throwInternalError)(`flowSurfaces applyApprovalBlueprint taskCard setLayout failed: ${message}`);
    }
  }
  async applyApprovalBlueprint(values, options = {}) {
    (0, import_authoring_validation.assertFlowSurfaceApprovalBlueprintAuthoringPayload)(values);
    const document = (0, import_blueprint.prepareFlowSurfaceApplyApprovalBlueprintDocument)(values);
    const bindingContext = await this.resolveApprovalBlueprintBindingContext(document, options.transaction);
    const surfaceRoot = await this.ensureApprovalBlueprintSurfaceRoot(bindingContext, options.transaction);
    await this.persistApprovalBlueprintBinding(bindingContext, surfaceRoot.rootUid, options.transaction);
    if (document.surface === "taskCard") {
      await this.applyApprovalBlueprintTaskCardSurface(document, surfaceRoot, bindingContext, options);
    } else {
      await this.applyApprovalBlueprintPageSurface(document, surfaceRoot, options);
    }
    await this.deps.syncApprovalRuntimeConfigForSurfaceRoot({ uid: surfaceRoot.rootUid }, options.transaction);
    let surface;
    try {
      surface = await this.deps.get(
        {
          uid: surfaceRoot.rootUid
        },
        options
      );
    } catch (error) {
      const message = error instanceof Error ? error.message : String(error);
      (0, import_errors.throwInternalError)(
        `flowSurfaces applyApprovalBlueprint readback failed for '${surfaceRoot.rootUid}': ${message}`
      );
    }
    return {
      version: "1",
      mode: document.mode,
      surfaceType: document.surface,
      target: (0, import_service_utils.buildDefinedPayload)({
        uid: surfaceRoot.rootUid,
        workflowId: bindingContext.workflowId,
        nodeId: bindingContext.nodeId
      }),
      binding: {
        resourceName: bindingContext.bindingResource,
        filterByTk: bindingContext.filterByTk,
        configPath: `config.${bindingContext.rootUidKey}`
      },
      surface
    };
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FlowSurfaceApprovalBlueprintService
});
