// src/analytics/count-resources.js
import { glob } from "glob";
var RESOURCE_PATTERNS = {
  events: ["**/events/*/index.@(md|mdx)"],
  commands: ["**/commands/*/index.@(md|mdx)"],
  queries: ["**/queries/*/index.@(md|mdx)"],
  services: ["**/services/*/index.@(md|mdx)"],
  domains: ["domains/*/index.@(md|mdx)", "domains/*/subdomains/*/index.@(md|mdx)"],
  flows: ["**/flows/*/index.@(md|mdx)"],
  channels: ["**/channels/**/index.@(md|mdx)"],
  entities: ["**/entities/*/index.@(md|mdx)"],
  containers: ["**/containers/**/index.@(md|mdx)"],
  "data-products": ["**/data-products/*/index.@(md|mdx)"],
  teams: ["teams/*.@(md|mdx)"],
  users: ["users/*.@(md|mdx)"],
  designs: ["**/*.ecstudio"],
  diagrams: ["**/diagrams/**/index.@(md|mdx)"],
  ubiquitousLanguages: ["domains/*/ubiquitous-language.@(md|mdx)", "domains/*/subdomains/*/ubiquitous-language.@(md|mdx)"]
};
async function countResources(projectDir) {
  const counts = {};
  for (const [type, patterns] of Object.entries(RESOURCE_PATTERNS)) {
    let total = 0;
    for (const pattern of patterns) {
      const files = await glob(pattern, {
        cwd: projectDir,
        ignore: ["**/versioned/**", "**/dist/**", "**/node_modules/**"]
      });
      total += files.length;
    }
    counts[type] = total;
  }
  return counts;
}
function serializeCounts(counts) {
  return Object.entries(counts).map(([k, v]) => `${k}:${v}`).join(",");
}

export {
  countResources,
  serializeCounts
};
