import {
  resolveProjectConfig
} from "./chunk-J3O64D2A.js";
import {
  resultToMcpResponse
} from "./chunk-EPUKTTJZ.js";
import {
  sanitizePath
} from "./chunk-W6Y7ZW3Y.js";

// src/mcp/tools/architecture.ts
var checkDependenciesDefinition = {
  name: "check_dependencies",
  description: "Validate layer boundaries and detect circular dependencies",
  inputSchema: {
    type: "object",
    properties: {
      path: { type: "string", description: "Path to project root" }
    },
    required: ["path"]
  }
};
async function handleCheckDependencies(input) {
  let projectPath;
  try {
    projectPath = sanitizePath(input.path);
  } catch (error) {
    return {
      content: [
        {
          type: "text",
          text: `Error: ${error instanceof Error ? error.message : String(error)}`
        }
      ],
      isError: true
    };
  }
  const configResult = resolveProjectConfig(projectPath);
  if (!configResult.ok) return resultToMcpResponse(configResult);
  try {
    const { validateDependencies, TypeScriptParser } = await import("./dist-TG63OKA5.js");
    const config = configResult.value;
    const rawLayers = Array.isArray(config.layers) ? config.layers : [];
    const layers = rawLayers.map((l) => ({
      name: l.name,
      patterns: [l.pattern],
      allowedDependencies: l.allowedDependencies
    }));
    const parser = new TypeScriptParser();
    const { loadGraphStore } = await import("./graph-loader-TIVI6NQ7.js");
    const store = await loadGraphStore(projectPath);
    let graphDependencyData;
    if (store) {
      const { GraphConstraintAdapter } = await import("./dist-PGQ32ZI7.js");
      const adapter = new GraphConstraintAdapter(store);
      const graphData = adapter.computeDependencyGraph();
      graphDependencyData = {
        nodes: [...graphData.nodes],
        edges: graphData.edges.map((e) => ({ ...e }))
      };
    }
    const result = await validateDependencies({
      layers,
      rootDir: projectPath,
      parser,
      ...graphDependencyData !== void 0 && { graphDependencyData }
    });
    return resultToMcpResponse(result);
  } catch (error) {
    return {
      content: [
        {
          type: "text",
          text: `Error: ${error instanceof Error ? error.message : String(error)}`
        }
      ],
      isError: true
    };
  }
}

export {
  checkDependenciesDefinition,
  handleCheckDependencies
};
