"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 solidity_exports = {};
__export(solidity_exports, {
  solidityLayerDetector: () => solidityLayerDetector
});
module.exports = __toCommonJS(solidity_exports);
var import_picomatch = __toESM(require("picomatch"));
const LAYER_PATTERNS = [
  // Core contracts (business logic)
  ["service", "**/contracts/**", 0.85],
  ["service", "**/src/**/*.sol", 0.8],
  // Interfaces (API surface)
  ["api", "**/interfaces/**", 0.95],
  ["api", "**/contracts/interfaces/**", 0.95],
  ["api", "**/src/interfaces/**", 0.95],
  ["api", "**/IInterface*.sol", 0.85],
  ["api", "**/I[A-Z]*.sol", 0.8],
  // Libraries (shared utilities)
  ["shared", "**/libraries/**", 0.9],
  ["shared", "**/contracts/libraries/**", 0.9],
  ["shared", "**/contracts/utils/**", 0.85],
  ["shared", "**/contracts/lib/**", 0.85],
  ["shared", "**/lib/**", 0.8],
  // Data layer (storage, models)
  ["data", "**/contracts/storage/**", 0.9],
  ["data", "**/contracts/models/**", 0.85],
  ["data", "**/migrations/**", 0.9],
  ["data", "**/deploy/**", 0.8],
  ["data", "**/script/**", 0.8],
  // Test layer (not a standard arch layer but useful for classification)
  ["shared", "**/test/**", 0.75],
  ["shared", "**/tests/**", 0.75],
  ["shared", "**/mocks/**", 0.8],
  ["shared", "**/contracts/mocks/**", 0.85]
];
const solidityLayerDetector = {
  language: "solidity",
  async detect(files, _projectRoot, configLayers) {
    const results = [];
    const configMatchers = _buildConfigMatchers(configLayers ?? {});
    for (const file of files) {
      if (!file.endsWith(".sol")) 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 = {
  solidityLayerDetector
});
//# sourceMappingURL=solidity.js.map
