# ===================================================================
# Docker Compose - Client Applications
# Meldestelle Project - Frontend Components
# ===================================================================
# Usage Scenarios:
#
# 1. STANDALONE CLIENT DEPLOYMENT (Fixed):
#    docker-compose -f docker-compose.clients.yml up -d
#    - Clients run independently without api-gateway dependency
#    - Set GATEWAY_HOST environment variable to external API Gateway
#    - Example: GATEWAY_HOST=localhost docker-compose -f docker-compose.clients.yml up -d
#
# 2. MULTI-FILE WITH INFRASTRUCTURE:
#    docker-compose -f docker-compose.yml -f docker-compose.clients.yml up -d
#    - Infrastructure services (api-gateway, postgres, etc.) start first
#    - Clients connect to api-gateway in same network
#
# 3. COMPLETE SYSTEM:
#    docker-compose -f docker-compose.yml -f docker-compose.services.yml -f docker-compose.clients.yml up -d
#    - Full stack: Infrastructure + Backend Services + Frontend Clients
# ===================================================================

services:
  # ===================================================================
  # Web Application (Kotlin/JS + Nginx)
  # ===================================================================
  web-app:
    build:
      context: .
      dockerfile: dockerfiles/clients/web-app/Dockerfile
      args:
        - BUILD_DATE=${BUILD_DATE:-$(date -u +"%Y-%m-%dT%H:%M:%SZ")}
        - VERSION=${APP_VERSION:-1.0.0}
    container_name: meldestelle-web-app
    environment:
      NODE_ENV: ${NODE_ENV:-production}
      APP_TITLE: ${APP_NAME:-Meldestelle}
      APP_VERSION: ${APP_VERSION:-1.0.0}
      # Nginx Worker Processes (für Performance)
      NGINX_WORKER_PROCESSES: ${NGINX_WORKER_PROCESSES:-auto}
    ports:
      - "4000:4000"
    networks:
      - meldestelle-network
    # depends_on removed for standalone client deployment
    # When using multi-file setup, api-gateway dependency is handled externally
    healthcheck:
      test: [ "CMD", "curl", "--fail", "http://localhost:4000/health" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-app.rule=Host(`localhost`) && PathPrefix(`/`)"
      - "traefik.http.services.web-app.loadbalancer.server.port=4000"

  # ===================================================================
  # Desktop Application (Kotlin Desktop + VNC)
  # ===================================================================
  #  desktop-app:
  #    build:
  #      context: .
  #      dockerfile: dockerfiles/clients/desktop-app/Dockerfile
  #    container_name: meldestelle-desktop-app
  #    environment:
  #      # API Configuration - fallback to external gateway if not in same compose network
  #      API_BASE_URL: http://${GATEWAY_HOST:-api-gateway}:${GATEWAY_PORT:-8081}
  #      # VNC Configuration
  #      DISPLAY: ":99"
  #      VNC_PORT: "5901"
  #      NOVNC_PORT: "6080"
  #      # App Information
  #      APP_TITLE: ${APP_NAME:-Meldestelle}
  #      APP_VERSION: ${APP_VERSION:-1.0.0}
  #    ports:
  #      - "6080:6080"  # Web-based VNC (noVNC)
  #      - "5901:5901"  # VNC direct access
  #    networks:
  #      - meldestelle-network
  #    # depends_on removed for standalone client deployment
  #    # When using multi-file setup, api-gateway dependency is handled externally
  #    healthcheck:
  #      test: [ "CMD", "/opt/health-check.sh" ]
  #      interval: 30s
  #      timeout: 10s
  #      retries: 3
  #      start_period: 60s
  #    restart: unless-stopped
  #    labels:
  #      - "traefik.enable=true"
  #      - "traefik.http.routers.desktop-app.rule=Host(`localhost`) && PathPrefix(`/desktop`)"
  #      - "traefik.http.services.desktop-app.loadbalancer.server.port=6080"

  # ===================================================================
  # Auth Server (Custom Keycloak Extension)
  # ===================================================================
#  auth-server:
#    build:
#      context: .
#      dockerfile: dockerfiles/infrastructure/auth-server/Dockerfile
#      args:
#        # Global build arguments (from docker/build-args/global.env)
#        GRADLE_VERSION: ${DOCKER_GRADLE_VERSION:-9.0.0}
#        JAVA_VERSION: ${DOCKER_JAVA_VERSION:-21}
#        BUILD_DATE: ${BUILD_DATE}
#        VERSION: ${DOCKER_APP_VERSION:-1.0.0}
#        # Infrastructure-specific arguments (from docker/build-args/infrastructure.env)
#        SPRING_PROFILES_ACTIVE: ${DOCKER_SPRING_PROFILES_DEFAULT:-default}
#    container_name: meldestelle-auth-server
#    environment:
#      SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-dev}
#      SERVER_PORT: ${AUTH_SERVICE_PORT:-8087}
#      KEYCLOAK_SERVER_URL: http://keycloak:8080
#      KEYCLOAK_REALM: meldestelle
#      KEYCLOAK_CLIENT_ID: meldestelle-auth-service
#      KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_CLIENT_SECRET:-auth-service-secret}
#      DB_HOST: postgres
#      DB_PORT: 5432
#      DB_NAME: ${POSTGRES_DB:-meldestelle}
#      DB_USER: ${POSTGRES_USER:-meldestelle}
#      DB_PASSWORD: ${POSTGRES_PASSWORD:-meldestelle}
#      JWT_SECRET: ${JWT_SECRET:-meldestelle-jwt-secret-key-for-development-change-in-production}
#      JWT_ISSUER: ${JWT_ISSUER:-meldestelle-api}
#      JWT_AUDIENCE: ${JWT_AUDIENCE:-meldestelle-clients}
#    ports:
#      - "${AUTH_SERVICE_PORT:-8087}:${AUTH_SERVICE_PORT:-8087}"
#    networks:
#      - meldestelle-network
#    healthcheck:
#      test: [ "CMD", "curl", "--fail", "http://localhost:${AUTH_SERVICE_PORT:-8087}/actuator/health" ]
#      interval: 30s
#      timeout: 10s
#      retries: 3
#      start_period: 60s
#    restart: unless-stopped

  # ===================================================================
  # Monitoring Server (Custom Grafana Extensions)
  # ===================================================================
#  monitoring-server:
#    build:
#      context: .
#      dockerfile: dockerfiles/infrastructure/monitoring-server/Dockerfile
#      args:
#        # Global build arguments (from docker/build-args/global.env)
#        GRADLE_VERSION: ${DOCKER_GRADLE_VERSION:-9.0.0}
#        JAVA_VERSION: ${DOCKER_JAVA_VERSION:-21}
#        BUILD_DATE: ${BUILD_DATE}
#        VERSION: ${DOCKER_APP_VERSION:-1.0.0}
#        # Infrastructure-specific arguments (from docker/build-args/infrastructure.env)
#        SPRING_PROFILES_ACTIVE: ${DOCKER_SPRING_PROFILES_DEFAULT:-default}
#    container_name: meldestelle-monitoring-server
#    environment:
#      SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-dev}
#      SERVER_PORT: 8088
#      GRAFANA_URL: http://grafana:3000
#      PROMETHEUS_URL: http://prometheus:9090
#      GRAFANA_ADMIN_USER: ${GF_SECURITY_ADMIN_USER:-admin}
#      GRAFANA_ADMIN_PASSWORD: ${GF_SECURITY_ADMIN_PASSWORD:-admin}
#      METRICS_AUTH_USERNAME: ${METRICS_AUTH_USERNAME:-admin}
#      METRICS_AUTH_PASSWORD: ${METRICS_AUTH_PASSWORD:-metrics}
#    ports:
#      - "8088:8088"
#    networks:
#      - meldestelle-network
#    healthcheck:
#      test: ["CMD", "curl", "--fail", "http://localhost:8088/actuator/health"]
#      interval: 30s
#      timeout: 10s
#      retries: 3
#      start_period: 60s
#    restart: unless-stopped
#    volumes:
#      - monitoring-data:/app/data
#      - ./docker/monitoring:/app/config:ro

# ===================================================================
# Volumes für Client-spezifische Daten
# ===================================================================
volumes:
  monitoring-data:
    driver: local
  desktop-app-gradle-cache:
    driver: local
  web-app-gradle-cache:
    driver: local

# ===================================================================
# Networks (shared network from main compose file)
# ===================================================================
networks:
  meldestelle-network:
    driver: bridge
