import {
  getEventCatalogConfigFile
} from "./chunk-6QENHZZP.js";

// src/resolve-catalog-dependencies.js
import path from "path";
import fs from "fs";
import matter from "gray-matter";
var resolve_catalog_dependencies_default = async (catalogDir, core) => {
  const catalogConfig = await getEventCatalogConfigFile(catalogDir);
  const dependencies = catalogConfig?.dependencies ?? null;
  if (!dependencies) {
    return;
  }
  const dependenciesDir = path.join(catalogDir, "dependencies");
  if (fs.existsSync(dependenciesDir)) {
    fs.rmSync(dependenciesDir, { recursive: true, force: true });
  }
  fs.mkdirSync(dependenciesDir, { recursive: true });
  const resourceTypes = Object.keys(dependencies);
  for (const resourceType of resourceTypes) {
    for (const dependency of dependencies[resourceType]) {
      const frontmatter = {
        id: dependency.id,
        name: dependency.id,
        version: dependency.version || "1.0.0"
      };
      const markdown = matter.stringify(
        {
          content: [
            ":::warning",
            "You are running EventCatalog with dependencies enabled.",
            "This resource is mocked and is a dependency. This means that the resource is managed and owned by another catalog.",
            ":::"
          ].join("\n\n")
        },
        frontmatter
      );
      const resourceFile = path.join(dependenciesDir, resourceType, dependency.id, `index.md`);
      fs.mkdirSync(path.dirname(resourceFile), { recursive: true });
      fs.writeFileSync(resourceFile, markdown);
    }
  }
  return;
};

export {
  resolve_catalog_dependencies_default
};
