version: '3.8'

services:
  # -----------------------------------------------------------------------------
  # Production Application Instance
  # -----------------------------------------------------------------------------
  app-prod:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: special-hotel-prod
    restart: unless-stopped
    ports:
      - "127.0.0.1:3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=${DATABASE_URL}
      - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
      - N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL}
      - N8N_WEBHOOK_SECRET=${N8N_WEBHOOK_SECRET}
    # Log tag prefix for syslog / journald, or environment labeling for standard output
    logging:
      driver: "json-file"
      options:
        tag: "app-prod/{{.Name}}"
        max-size: "10m"
        max-file: "3"
    networks:
      - default
      - proxy

  # -----------------------------------------------------------------------------
  # Development & Testing Application Instance
  # -----------------------------------------------------------------------------
  app-dev:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: special-hotel-dev
    restart: no # Do not auto-restart if variables are missing or if it gracefully stops
    ports:
      - "127.0.0.1:3001:3000"
    environment:
      - NODE_ENV=development
      - DATABASE_URL=${DATABASE_URL_DEV}
      - TEST_DATABASE_URL=${TEST_DATABASE_URL}
      - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL_DEV}
      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET_DEV}
      - N8N_TEST_WEBHOOK_URL=${N8N_TEST_WEBHOOK_URL}
      - N8N_WEBHOOK_SECRET=${N8N_WEBHOOK_SECRET_DEV}
    # Commands run a pre-startup verification. If development-exclusive 
    # variables are missing, it logs a warning and exits with code 0 (graceful exit).
    entrypoint: >
      /bin/sh -c "
      if [ -z \"$${TEST_DATABASE_URL}\" ] || [ -z \"$${N8N_TEST_WEBHOOK_URL}\" ]; then
        echo '[DEV] Required development-exclusive variables (TEST_DATABASE_URL, N8N_TEST_WEBHOOK_URL) are missing.';
        echo '[DEV] Gracefully shutting down the development service with exit code 0.';
        exit 0;
      fi;
      echo '[DEV] Starting Next.js development server...';
      exec npm run dev
      "
    logging:
      driver: "json-file"
      options:
        tag: "app-dev/{{.Name}}"
        max-size: "10m"
        max-file: "3"
    networks:
      - default
      - proxy

  # -----------------------------------------------------------------------------
  # Walkthrough/Demo Application Instance
  # -----------------------------------------------------------------------------
  app-walkthrough:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: special-hotel-walkthrough
    restart: unless-stopped
    ports:
      - "127.0.0.1:3002:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=${DATABASE_URL_WALKTHROUGH}
      - NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL_WALKTHROUGH}
      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET_WALKTHROUGH}
      - N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL_WALKTHROUGH}
      - N8N_WEBHOOK_SECRET=${N8N_WEBHOOK_SECRET_WALKTHROUGH}
    logging:
      driver: "json-file"
      options:
        tag: "app-walkthrough/{{.Name}}"
        max-size: "10m"
        max-file: "3"
    networks:
      - default
      - proxy

networks:
  default:
  proxy:
    external: true

