"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 go_exports = {};
__export(go_exports, {
  goLayerDetector: () => goLayerDetector
});
module.exports = __toCommonJS(go_exports);
var import_picomatch = __toESM(require("picomatch"));
const LAYER_PATTERNS = [
  // API layer (cmd = entry points, handler = HTTP handlers)
  ["api", "**/cmd/**", 0.85],
  ["api", "**/handler/**", 0.9],
  ["api", "**/handlers/**", 0.9],
  ["api", "**/*_handler.go", 0.9],
  ["api", "**/delivery/**", 0.85],
  ["api", "**/transport/**", 0.85],
  ["api", "**/http/**", 0.85],
  ["api", "**/grpc/**", 0.85],
  ["api", "**/api/**", 0.8],
  // Service layer
  ["service", "**/service/**", 0.9],
  ["service", "**/services/**", 0.9],
  ["service", "**/*_service.go", 0.9],
  ["service", "**/usecase/**", 0.9],
  ["service", "**/usecases/**", 0.9],
  ["service", "**/domain/**", 0.8],
  ["service", "**/business/**", 0.85],
  // Data layer
  ["data", "**/repository/**", 0.9],
  ["data", "**/repositories/**", 0.9],
  ["data", "**/*_repository.go", 0.9],
  ["data", "**/*_repo.go", 0.9],
  ["data", "**/store/**", 0.85],
  ["data", "**/storage/**", 0.85],
  ["data", "**/db/**", 0.85],
  ["data", "**/models/**", 0.8],
  ["data", "**/entities/**", 0.8],
  ["data", "**/migrations/**", 0.85],
  // Shared / infrastructure layer
  ["shared", "**/pkg/**", 0.8],
  ["shared", "**/internal/**", 0.75],
  ["shared", "**/util/**", 0.85],
  ["shared", "**/utils/**", 0.85],
  ["shared", "**/common/**", 0.8],
  ["shared", "**/config/**", 0.8],
  ["shared", "**/middleware/**", 0.85],
  ["shared", "**/logger/**", 0.8]
];
const goLayerDetector = {
  language: "go",
  async detect(files, _projectRoot, configLayers) {
    const results = [];
    const configMatchers = _buildConfigMatchers(configLayers ?? {});
    for (const file of files) {
      if (!file.endsWith(".go")) 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 = {
  goLayerDetector
});
//# sourceMappingURL=go.js.map
