"use strict";
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 rust_exports = {};
__export(rust_exports, {
  rustLayerDetector: () => rustLayerDetector
});
module.exports = __toCommonJS(rust_exports);
var import_picomatch = __toESM(require("picomatch"));
const LAYER_PATTERNS = [
  ["api", "**/handlers/**", 0.9],
  ["api", "**/routes/**", 0.9],
  ["api", "**/*_handler.rs", 0.9],
  ["api", "**/*_route.rs", 0.85],
  ["service", "**/services/**", 0.9],
  ["service", "**/service/**", 0.9],
  ["service", "**/*_service.rs", 0.9],
  ["service", "**/domain/**", 0.8],
  ["data", "**/models/**", 0.85],
  ["data", "**/repositories/**", 0.9],
  ["data", "**/*_repository.rs", 0.9],
  ["data", "**/db/**", 0.85],
  ["data", "**/schema.rs", 0.85],
  ["data", "**/migrations/**", 0.85],
  ["shared", "**/utils/**", 0.85],
  ["shared", "**/common/**", 0.8],
  ["shared", "**/config/**", 0.8],
  ["shared", "**/errors.rs", 0.75],
  ["shared", "**/error.rs", 0.75]
];
const rustLayerDetector = {
  language: "rust",
  async detect(files, _projectRoot, configLayers) {
    const results = [];
    const configMatchers = _buildConfigMatchers(configLayers ?? {});
    for (const file of files) {
      if (!file.endsWith(".rs")) continue;
      const configMatch = _matchConfig(file, configMatchers);
      if (configMatch) {
        results.push({ ...configMatch, filePath: file });
        continue;
      }
      let best = null;
      for (const [layerName, pattern, confidence] of LAYER_PATTERNS) {
        if ((0, import_picomatch.default)(pattern)(file)) {
          if (!best || confidence > best.confidence) {
            best = { layerName, filePath: file, confidence, matchedPattern: pattern };
          }
        }
      }
      if (best) results.push(best);
    }
    return results;
  }
};
function _buildConfigMatchers(configLayers) {
  return Object.entries(configLayers).flatMap(
    ([layerName, patterns]) => patterns.map(
      (pattern) => [layerName, (0, import_picomatch.default)(pattern), pattern]
    )
  );
}
function _matchConfig(file, matchers) {
  for (const [layerName, matcher, pattern] of matchers) {
    if (matcher(file)) return { layerName, confidence: 1, matchedPattern: `config:${pattern}` };
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  rustLayerDetector
});
//# sourceMappingURL=rust.js.map
