"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 pulumi_exports = {};
__export(pulumi_exports, {
  pulumiResolver: () => pulumiResolver
});
module.exports = __toCommonJS(pulumi_exports);
const pulumiResolver = {
  name: "pulumi",
  detect(context) {
    if (context.fileExists("Pulumi.yaml") || context.fileExists("Pulumi.yml")) return true;
    const pkg = context.readFile("package.json");
    if (pkg) {
      try {
        const parsed = JSON.parse(pkg);
        const deps = { ...parsed.dependencies, ...parsed.devDependencies };
        if (Object.keys(deps).some((d) => d.startsWith("@pulumi/"))) return true;
      } catch {
      }
    }
    const requirements = context.readFile("requirements.txt");
    if (requirements && requirements.includes("pulumi")) return true;
    return false;
  },
  resolve(ref, context) {
    if (/^[a-z][a-zA-Z0-9]*\.[a-zA-Z]/.test(ref.referenceName)) {
      const varName = ref.referenceName.split(".")[0];
      const id = resolveInDirs(varName, ["index", "src", "infra", "infrastructure", "lib"], context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.75, resolvedBy: "framework" };
    }
    if (/^[A-Z][a-zA-Z]+$/.test(ref.referenceName)) {
      const id = resolveInDirs(ref.referenceName, ["components", "src", "infra", "lib"], context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.7, resolvedBy: "framework" };
    }
    return null;
  },
  extractNodes(filePath, content) {
    const nodes = [];
    const now = Date.now();
    const routePattern = /path\s*:\s*["']([^"']+)["'][^}]*method\s*:\s*["'](\w+)["']/g;
    let match;
    while ((match = routePattern.exec(content)) !== null) {
      const line = content.slice(0, match.index).split("\n").length;
      const routePath = match[1];
      const method = match[2].toUpperCase();
      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: filePath.endsWith(".py") ? "python" : "typescript",
        updatedAt: now
      });
    }
    return nodes;
  }
};
function resolveInDirs(name, dirs, context) {
  for (const file of context.getAllFiles()) {
    if (!(file.endsWith(".ts") || file.endsWith(".js") || file.endsWith(".py") || file.endsWith(".go"))) continue;
    if (!dirs.some((d) => file.includes(`/${d}/`) || file.includes(`/${d}.`))) continue;
    const node = context.getNodesInFile(file).find((n) => n.name === name);
    if (node) return node.id;
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  pulumiResolver
});
//# sourceMappingURL=pulumi.js.map
