// apps/cli/src/templates/digitalocean.ts

/** Generate a .do/app.yaml for DigitalOcean App Platform */
export const doAppSpecTemplate = (
  agentName: string,
  region: string = "nyc",
) => `# DigitalOcean App Platform Spec — raxd agent
# Generated by: rax deploy up --target digitalocean
# Docs: https://docs.digitalocean.com/products/app-platform/reference/app-spec/
#
# Deploy:
#   doctl apps create --spec .do/app.yaml
#   doctl apps update <app-id> --spec .do/app.yaml

name: raxd-${agentName}
region: ${region}

services:
  - name: agent
    dockerfile_path: Dockerfile
    http_port: 3000
    instance_count: 1
    instance_size_slug: basic-xxs
    health_check:
      http_path: /health
      initial_delay_seconds: 15
      period_seconds: 30
      timeout_seconds: 5
      success_threshold: 1
      failure_threshold: 3
    envs:
      - key: PORT
        value: "3000"
      - key: LLM_PROVIDER
        value: anthropic
      - key: LLM_MODEL
        value: claude-sonnet-4-20250514
      - key: ANTHROPIC_API_KEY
        type: SECRET
        value: REPLACE_ME
      - key: TAVILY_API_KEY
        type: SECRET
        value: REPLACE_ME
    routes:
      - path: /
`;

/**
 * DigitalOcean GPU Droplet docker-compose for local model support.
 * DO has great GPU droplets — this pairs well with Ollama.
 */
export const doGpuComposeTemplate = (
  agentName: string,
) => `# DigitalOcean GPU Droplet — raxd agent + Ollama
# Generated by: rax deploy up --target digitalocean --gpu
# Docs: https://docs.digitalocean.com/products/droplets/details/gpu/
#
# Deploy to a GPU Droplet:
#   1. Create a GPU Droplet (H100, A100, or L40S)
#   2. SSH in: ssh root@<droplet-ip>
#   3. Clone your repo
#   4. docker compose -f docker-compose.gpu.yml up -d
#
# This runs your agent alongside a local Ollama instance,
# eliminating the need for external API keys.

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama-data:/root/.ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

  agent:
    build: .
    container_name: raxd-${agentName}
    restart: unless-stopped
    depends_on:
      - ollama
    environment:
      PORT: "3000"
      LLM_PROVIDER: ollama
      LLM_MODEL: qwen3:14b
      OLLAMA_BASE_URL: http://ollama:11434
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges
    deploy:
      resources:
        limits:
          memory: 1g
    volumes:
      - agent-data:/app/data
    ports:
      - "3000:3000"

  # Optional: model pull on startup
  model-pull:
    image: curlimages/curl:latest
    depends_on:
      - ollama
    restart: "no"
    entrypoint: >
      sh -c "sleep 10 && curl -s http://ollama:11434/api/pull -d '{\"name\": \"qwen3:14b\"}'"

volumes:
  ollama-data:
  agent-data:
`;
