// apps/cli/src/templates/compose.ts

export const composeSingleTemplate = (
  agentName: string,
) => `# raxd — Docker Compose (single topology)
# Generated by: rax deploy init --topology single
#
# Usage:
#   docker compose up -d
#   docker compose logs -f
#   curl http://localhost:3000/health

services:
  agent:
    build: .
    container_name: raxd-${agentName}
    restart: unless-stopped
    env_file: .env.production
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges
    deploy:
      resources:
        limits:
          memory: 512m
          pids: 50
    volumes:
      - agent-data:/app/data
    ports:
      - "\${HEALTH_PORT:-3000}:3000"

  # ── Uncomment for production (replaces SQLite) ──────────────────────────
  # postgres:
  #   image: postgres:17-alpine
  #   restart: unless-stopped
  #   environment:
  #     POSTGRES_DB: raxd
  #     POSTGRES_USER: raxd
  #     POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
  #   volumes:
  #     - pgdata:/var/lib/postgresql/data
  #   healthcheck:
  #     test: ["CMD-SHELL", "pg_isready -U raxd"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 5

volumes:
  agent-data:
  # pgdata:
`;

/** Monorepo-aware compose. Build context = workspace root. */
export const composeMonorepoTemplate = (
  agentName: string,
  appPath: string,
  contextPath: string,
) => `# raxd — Docker Compose (monorepo single topology)
# Generated by: rax deploy init --topology single
#
# Usage:
#   docker compose up -d
#   docker compose logs -f
#   curl http://localhost:3000/health

services:
  agent:
    build:
      context: ${contextPath}
      dockerfile: ${appPath}/Dockerfile
    container_name: raxd-${agentName}
    restart: unless-stopped
    env_file: .env.production
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges
    deploy:
      resources:
        limits:
          memory: 512m
          pids: 50
    volumes:
      - agent-data:/app/data
      - drafts:/app/${appPath}/drafts
    ports:
      - "\${HEALTH_PORT:-3000}:3000"

  # ── Uncomment for production (replaces SQLite) ──────────────────────────
  # postgres:
  #   image: postgres:17-alpine
  #   restart: unless-stopped
  #   environment:
  #     POSTGRES_DB: raxd
  #     POSTGRES_USER: raxd
  #     POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}
  #   volumes:
  #     - pgdata:/var/lib/postgresql/data
  #   healthcheck:
  #     test: ["CMD-SHELL", "pg_isready -U raxd"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 5

volumes:
  agent-data:
  drafts:
  # pgdata:
`;
