services:
  app:
    build:
      context: .
      args:
        APP_VERSION: ${APP_VERSION:-4.0.2}
    container_name: goodwalk_svelte_app
    environment:
      APP_VERSION: ${APP_VERSION:-4.0.2}
      DATABASE_URL: postgresql://${POSTGRES_USER:-goodwalk}:${POSTGRES_PASSWORD_URLENCODED:-goodwalk}@db:5432/${POSTGRES_DB:-goodwalk}
      NODE_ENV: production
      PORT: 3000
      ENABLE_GENERAL_ENQUIRIES: ${ENABLE_GENERAL_ENQUIRIES:-false}
      TZ: ${TZ:-Pacific/Auckland}
    depends_on:
      - db
    expose:
      - '3000'
    restart: unless-stopped
    networks:
      - default
      - webnet

  mail-api:
    build:
      context: ./mail-api
      args:
        APP_VERSION: ${APP_VERSION:-4.0.2}
    container_name: goodwalk_svelte_mail_api
    environment:
      APP_VERSION: ${APP_VERSION:-4.0.2}
      RESEND_API_KEY: ${RESEND_API_KEY}
      OWNER_EMAIL: ${OWNER_EMAIL}
      OWNER_BCC: ${OWNER_BCC:-}
      CLIENT_BCC: ${CLIENT_BCC:-}
      FROM_EMAIL: ${FROM_EMAIL:-GoodWalk <bookings@goodwalk.co.nz>}
      REPLY_TO: ${REPLY_TO:-aless@goodwalk.co.nz}
      ENABLE_GENERAL_ENQUIRIES: ${ENABLE_GENERAL_ENQUIRIES:-false}
      FORM_MIN_SECONDS: ${FORM_MIN_SECONDS:-4}
      FORM_MAX_SECONDS: ${FORM_MAX_SECONDS:-7200}
      RATE_LIMIT_WINDOW_SECONDS: ${RATE_LIMIT_WINDOW_SECONDS:-900}
      RATE_LIMIT_MAX_PER_IP: ${RATE_LIMIT_MAX_PER_IP:-5}
      RATE_LIMIT_MAX_PER_EMAIL: ${RATE_LIMIT_MAX_PER_EMAIL:-3}
      RATE_LIMIT_MIN_INTERVAL_SECONDS: ${RATE_LIMIT_MIN_INTERVAL_SECONDS:-20}
      PYTHONUNBUFFERED: '1'
      TZ: ${TZ:-Pacific/Auckland}
    expose:
      - '8000'
    restart: unless-stopped
    networks:
      - default
      - webnet

  db:
    image: postgres:16-alpine
    container_name: goodwalk_svelte_db
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-goodwalk}
      POSTGRES_USER: ${POSTGRES_USER:-goodwalk}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-goodwalk}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./docker/postgres/init:/docker-entrypoint-initdb.d:ro
    restart: unless-stopped
    networks:
      - default

volumes:
  postgres_data:

networks:
  webnet:
    external: true
