"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var layers_exports = {};
__export(layers_exports, {
  buildArchLayers: () => buildArchLayers,
  detectAllLayers: () => detectAllLayers,
  getAllLayerDetectors: () => getAllLayerDetectors,
  registerLayerDetector: () => registerLayerDetector
});
module.exports = __toCommonJS(layers_exports);
var import_typescript = require("./typescript");
var import_python = require("./python");
var import_go = require("./go");
var import_java = require("./java");
var import_ruby = require("./ruby");
var import_rust = require("./rust");
var import_csharp = require("./csharp");
var import_elixir = require("./elixir");
var import_scala = require("./scala");
var import_vue = require("./vue");
var import_solidity = require("./solidity");
var import_ocaml = require("./ocaml");
const LAYER_DETECTORS = [
  import_typescript.typescriptLayerDetector,
  import_python.pythonLayerDetector,
  import_go.goLayerDetector,
  import_java.javaLayerDetector,
  import_ruby.rubyLayerDetector,
  import_rust.rustLayerDetector,
  import_csharp.csharpLayerDetector,
  import_elixir.elixirLayerDetector,
  import_scala.scalaLayerDetector,
  import_vue.vueLayerDetector,
  import_solidity.solidityLayerDetector,
  import_ocaml.ocamlLayerDetector
];
function getAllLayerDetectors() {
  return LAYER_DETECTORS;
}
function registerLayerDetector(detector) {
  const idx = LAYER_DETECTORS.findIndex((d) => d.language === detector.language && d.framework === detector.framework);
  if (idx >= 0) LAYER_DETECTORS[idx] = detector;
  else LAYER_DETECTORS.push(detector);
}
async function detectAllLayers(files, projectRoot, configLayers) {
  const allMatches = [];
  for (const detector of LAYER_DETECTORS) {
    const matches = await detector.detect(files, projectRoot, configLayers);
    allMatches.push(...matches);
  }
  const best = /* @__PURE__ */ new Map();
  for (const match of allMatches) {
    const existing = best.get(match.filePath);
    if (!existing || match.confidence > existing.confidence) {
      best.set(match.filePath, match);
    }
  }
  return [...best.values()].map((m) => ({
    filePath: m.filePath,
    layerName: m.layerName,
    confidence: m.confidence,
    matchedPattern: m.matchedPattern
  }));
}
function buildArchLayers(assignments, configLayers) {
  const layerMap = /* @__PURE__ */ new Map();
  for (const a of assignments) {
    if (!layerMap.has(a.layerName)) {
      const isConfig = configLayers && a.layerName in configLayers;
      layerMap.set(a.layerName, {
        id: `layer:${a.layerName}`,
        name: a.layerName,
        source: isConfig ? "config" : "auto",
        patterns: [],
        updatedAt: Date.now()
      });
    }
    const layer = layerMap.get(a.layerName);
    if (!layer.patterns.includes(a.matchedPattern)) {
      layer.patterns.push(a.matchedPattern);
    }
  }
  return [...layerMap.values()];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildArchLayers,
  detectAllLayers,
  getAllLayerDetectors,
  registerLayerDetector
});
//# sourceMappingURL=index.js.map
