# =============================================================================
# Render Blueprint — provisions the app, PostgreSQL and Redis together.
#
#   1. Push this repo to GitHub
#   2. Render dashboard -> New -> Blueprint -> pick the repo
#   3. Set SEED_ADMIN_EMAIL and SEED_ADMIN_PASSWORD when prompted
#   4. Deploy
#
# The database URL, Redis URL and both secrets are wired automatically.
# On first boot the app creates its own schema and your admin login.
# =============================================================================

databases:
  - name: support-chat-db
    databaseName: support_chat
    user: support
    plan: free            # free Postgres is time-limited; upgrade before it lapses

services:
  # ---- Redis (Render calls this Key Value) --------------------------------
  # If your account rejects `keyvalue`, change the type to `redis` — the
  # option was renamed and older accounts still use the old name.
  - type: keyvalue
    name: support-chat-redis
    plan: free
    ipAllowList: []       # reachable only from inside Render

  # ---- the app ------------------------------------------------------------
  - type: web
    name: support-chat
    runtime: docker
    dockerfilePath: ./Dockerfile
    plan: starter         # `free` works but sleeps after ~15 min idle
    healthCheckPath: /health
    envVars:
      - key: NODE_ENV
        value: production
      - key: TRUST_PROXY
        value: "true"     # Render terminates TLS in front of the app

      # Wired automatically from the two services above.
      - key: DATABASE_URL
        fromDatabase:
          name: support-chat-db
          property: connectionString
      - key: REDIS_URL
        fromService:
          type: keyvalue
          name: support-chat-redis
          property: connectionString

      # Generated once by Render and then held constant.
      - key: JWT_SECRET
        generateValue: true
      - key: FILE_SIGNING_SECRET
        generateValue: true

      # First boot creates the schema and your admin account.
      - key: AUTO_MIGRATE
        value: "true"
      - key: SEED_ADMIN_EMAIL
        sync: false       # Render prompts you for this
      - key: SEED_ADMIN_PASSWORD
        sync: false       # ...and this. Choose a strong one.
      - key: SEED_ADMIN_NAME
        value: Admin

      # Small instance: stay well under Postgres max_connections.
      - key: PG_POOL_MAX
        value: "8"

      # Set these after the first deploy, once you know your URL.
      - key: PUBLIC_URL
        sync: false       # https://support-chat-xxxx.onrender.com
      - key: CORS_ORIGINS
        sync: false       # https://yourdomain.com
