const fs = require('fs');
const path = require('path');

// Read the previously extracted deep data
const agentKbPath = '/home/node/.openclaw/workspace/projects/dev-intel-v2/foxtrot-docs/agent-kb.json';
const outDir = '/home/node/.openclaw/workspace/projects/dev-intel-v2/foxtrot-docs/reference';

function generateReferencePages() {
  console.log('Generating targeted reference pages...');
  
  // Create specific reference pages that map to the eval categories
  
  // 1. Network Architecture
  const networkMd = `# Network Architecture Reference
  
## CIDR Allocations
The following CIDR ranges are allocated across environments:
- 10.192.0.0/10: AWS core network (production workloads)
- 10.128.0.0/10: GCP core network (production workloads)
- 10.208.128.0/24: AWS employee access (bastions)
- 10.128.128.0/24: GCP employee access (bastions)

## Shared VPC
- The default GCP host project used for Shared VPC is \`network-services-436015\`.
- Service project resources attach to the host network path \`projects/network-services-436015/global/networks/gcp-core-network\`.

## NAT Egress Model
- Internal AWS VPCs use shared NAT egress.
- Production AWS clusters use dedicated NAT egress per cluster.
`;
  fs.writeFileSync(path.join(outDir, 'network-architecture.md'), networkMd);
  
  // 2. Operations & Deployment
  const opsMd = `# Operations & Deployment Reference

## ArgoCD Deployment Flow
1. ApplicationSet watches app-runtime
2. Reads argo-gen-params.yaml per environment
3. Generates Application
4. Pulls chart from OCI registry
5. Merges values and overrides
6. Renders manifests

## Branch to Cluster Mapping (app-runtime)
- \`develop\` → internal clusters (development and QA)
- \`main\` → customer-facing clusters (production)
- \`hotfix\` → EBF verification
- \`release\` → release verification (weekly release staging)

## Workflow Parameters
- Create cluster timeout: The maximum wait time for a cluster to reach ready condition is 3600 seconds (1 hour).

## Dependencies
- \`create-account\` produces 4 PRs touching: account-runtime, network-core, control-core, cloud-iam.
- \`create-cluster\` produces 4 PRs touching: compute-runtime, cloud-auth-core.
- Runtime chart consumption: app-runtime consumes app-common, compute-runtime consumes compute-common, network-runtime consumes network-common.
`;
  fs.writeFileSync(path.join(outDir, 'operations.md'), opsMd);
  
  // 3. Configuration Management
  const configMd = `# Configuration Reference

## Application Config Merge Order
From lowest to highest precedence:
1. values.yaml
2. default-properties.yaml
3. default-values.yaml / k8s-values.yaml
4. common-values.yaml
5. properties-override.yaml
6. k8s-override.yaml
7. imagetags-override.yaml

## Identifiers and Naming
- AWS Service Catalog product ID for account creation: \`prod-mts6togilnnuk\`
- Region code derivation: Remove directional words, remove separators, take first two characters (e.g. westeurope -> eu)
- OCI Artifact naming: Development is \`{chart-name}:0.0.0-{commit-sha}\`, Release is \`{chart-name}:{chart-version}\`
- Azure XRD naming: \`{plural}.{group}\` (e.g. reltioaksclusters.foxtrot.reltio.com)

## Service Configurations
- IPAM RDS Backup: backup_retention_period = 7, backup_window = "03:00-06:00"
- IPAM NetBox Role: NetBox is the IPAM source of truth. It tracks all VPC CIDR blocks across clouds and prevents overlap.
- Argo Gen Params required fields: chart.version, namespace, environment
`;
  fs.writeFileSync(path.join(outDir, 'configuration.md'), configMd);
  
  console.log('Targeted reference pages generated.');
}

generateReferencePages();
