// apps/cli/src/templates/fly-toml.ts

/** Generate a fly.toml for Fly.io deployment */
export const flyTomlTemplate = (
  agentName: string,
  isMonorepo: boolean,
  appPath?: string,
) => `# Fly.io configuration for raxd agent
# Generated by: rax deploy up --target fly
# Docs: https://fly.io/docs/reference/configuration/

app = "raxd-${agentName}"
primary_region = "iad"

[build]
${isMonorepo ? `  dockerfile = "${appPath}/Dockerfile"` : "  dockerfile = \"Dockerfile\""}

[env]
  HEALTH_PORT = "3000"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = "stop"
  auto_start_machines = true
  min_machines_running = 1

  [http_service.concurrency]
    type = "connections"
    hard_limit = 25
    soft_limit = 20

[[services]]
  protocol = "tcp"
  internal_port = 3000

  [[services.ports]]
    port = 80
    handlers = ["http"]

  [[services.ports]]
    port = 443
    handlers = ["tls", "http"]

  [[services.tcp_checks]]
    grace_period = "10s"
    interval = "30s"
    timeout = "5s"

  [[services.http_checks]]
    grace_period = "10s"
    interval = "30s"
    method = "GET"
    path = "/health"
    protocol = "http"
    timeout = "5s"

[checks]
  [checks.health]
    grace_period = "10s"
    interval = "30s"
    method = "GET"
    path = "/health"
    port = 3000
    timeout = "5s"
    type = "http"

[[vm]]
  size = "shared-cpu-1x"
  memory = "512mb"
`;

/** Generate a fly.io Dockerfile (wraps existing Dockerfile for context) */
export const flyDockerfileNote = () =>
  "# Your existing Dockerfile works with Fly.io — no changes needed.\n" +
  "# Fly.io will use the Dockerfile specified in fly.toml.\n";
