// engine/infrastructure/kubernetes-generator.ts — Kubernetes manifest generator (SPEC-171)
function renderDeployment(component, env) {
    const replicas = env === 'prod' ? 3 : 1;
    return `apiVersion: apps/v1
kind: Deployment
metadata:
  name: ${component.name}
  namespace: ${env}
  labels:
    app: ${component.name}
    environment: ${env}
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      app: ${component.name}
  template:
    metadata:
      labels:
        app: ${component.name}
        environment: ${env}
    spec:
      containers:
        - name: ${component.name}
          image: your-registry/${component.name}:latest
          ports:
            - containerPort: 3000
          env:
            - name: NODE_ENV
              value: "${env}"
          resources:
            requests:
              memory: "${env === 'prod' ? '256Mi' : '128Mi'}"
              cpu: "${env === 'prod' ? '250m' : '100m'}"
            limits:
              memory: "${env === 'prod' ? '512Mi' : '256Mi'}"
              cpu: "${env === 'prod' ? '500m' : '200m'}"
          readinessProbe:
            httpGet:
              path: /health
              port: 3000
            initialDelaySeconds: 10
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /health
              port: 3000
            initialDelaySeconds: 30
            periodSeconds: 10
---
`;
}
function renderService(component, env) {
    return `apiVersion: v1
kind: Service
metadata:
  name: ${component.name}
  namespace: ${env}
  labels:
    app: ${component.name}
spec:
  selector:
    app: ${component.name}
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  type: ClusterIP
---
`;
}
function renderIngress(component, env) {
    const host = env === 'prod' ? `${component.name}.example.com` : `${component.name}.${env}.example.com`;
    return `apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ${component.name}
  namespace: ${env}
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - ${host}
      secretName: ${component.name}-tls
  rules:
    - host: ${host}
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: ${component.name}
                port:
                  number: 80
---
`;
}
function renderNamespace(env) {
    return `apiVersion: v1
kind: Namespace
metadata:
  name: ${env}
  labels:
    environment: ${env}
---
`;
}
/**
 * Generate Kubernetes manifests (Deployment + Service + Ingress) for API components.
 */
export function generateKubernetes(components, env) {
    const k8sComponents = components.filter((c) => ['k8s-deployment', 'k8s-service', 'k8s-ingress', 'ecs', 'api'].includes(c.kind));
    // Always include at least the namespace + a default app deployment
    const appComponents = k8sComponents.length > 0
        ? k8sComponents
        : [
            {
                kind: 'k8s-deployment',
                name: 'app',
                size: 'small',
                estimatedMonthlyCostUsd: 0,
                properties: {},
            },
        ];
    const manifests = [renderNamespace(env)];
    for (const component of appComponents) {
        manifests.push(renderDeployment(component, env));
        manifests.push(renderService(component, env));
        manifests.push(renderIngress(component, env));
    }
    return {
        format: 'kubernetes',
        filename: `k8s-${env}.yaml`,
        content: manifests.join('\n'),
    };
}
//# sourceMappingURL=kubernetes-generator.js.map