"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 scala_exports = {};
__export(scala_exports, {
  playResolver: () => playResolver
});
module.exports = __toCommonJS(scala_exports);
const playResolver = {
  name: "play",
  detect(context) {
    const buildSbt = context.readFile("build.sbt");
    if (buildSbt && (buildSbt.includes("PlayScala") || buildSbt.includes("play-"))) return true;
    const plugins = context.readFile("project/plugins.sbt");
    if (plugins && plugins.includes("sbt-plugin")) return true;
    return context.getAllFiles().some((f) => f.includes("/controllers/") && f.endsWith(".scala"));
  },
  resolve(ref, context) {
    if (ref.referenceName.endsWith("Controller")) {
      const id = resolveInDirs(ref.referenceName, ["controllers", "app/controllers"], ".scala", "class", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Service") || ref.referenceName.endsWith("Repository")) {
      const id = resolveInDirs(ref.referenceName, ["services", "repositories", "app/services", "app/repositories"], ".scala", null, context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.8, resolvedBy: "framework" };
    }
    if (/^[A-Z][a-zA-Z]+$/.test(ref.referenceName)) {
      const id = resolveInDirs(ref.referenceName, ["models", "app/models", "domain"], ".scala", "class", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.7, resolvedBy: "framework" };
    }
    return null;
  },
  extractNodes(filePath, content) {
    const nodes = [];
    const now = Date.now();
    if (filePath.endsWith("/routes") || filePath.endsWith("/routes.conf")) {
      const routePattern = /^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+(\S+)/gm;
      let match;
      while ((match = routePattern.exec(content)) !== null) {
        const line = content.slice(0, match.index).split("\n").length;
        const [, method, routePath] = match;
        const name = `${method} ${routePath}`;
        nodes.push({
          id: `route:${filePath}:${method}:${routePath}:${line}`,
          kind: "route",
          name,
          qualifiedName: `${filePath}::${name}`,
          filePath,
          startLine: line,
          endLine: line,
          startColumn: 0,
          endColumn: match[0].length,
          language: "scala",
          updatedAt: now
        });
      }
      return nodes;
    }
    const dslPatterns = [
      // Akka HTTP: path("users") { get { ... } }
      /(?:path|pathPrefix)\s*\(\s*"([^"]+)"\s*\)/g,
      // http4s: case GET -> Root / "users"
      /case\s+(GET|POST|PUT|PATCH|DELETE)\s+->\s+Root\s*\/\s*"([^"]+)"/g
    ];
    for (const pattern of dslPatterns) {
      let match;
      while ((match = pattern.exec(content)) !== null) {
        const line = content.slice(0, match.index).split("\n").length;
        const isHttp4s = pattern.source.includes("case");
        const method = isHttp4s ? match[1] : "ANY";
        const routePath = isHttp4s ? `/${match[2]}` : `/${match[1]}`;
        const name = `${method} ${routePath}`;
        const id = `route:${filePath}:${method}:${routePath}:${line}`;
        if (!nodes.some((n) => n.id === id)) {
          nodes.push({
            id,
            kind: "route",
            name,
            qualifiedName: `${filePath}::${name}`,
            filePath,
            startLine: line,
            endLine: line,
            startColumn: 0,
            endColumn: match[0].length,
            language: "scala",
            updatedAt: now
          });
        }
      }
    }
    return nodes;
  }
};
function resolveInDirs(name, dirs, ext, kind, context) {
  for (const file of context.getAllFiles()) {
    if (file.endsWith(ext) && dirs.some((d) => file.includes(`/${d}/`) || file.includes(`/${d}`))) {
      const node = context.getNodesInFile(file).find(
        (n) => n.name === name && (kind === null || n.kind === kind)
      );
      if (node) return node.id;
    }
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  playResolver
});
//# sourceMappingURL=scala.js.map
