# BreakPilot PWA - Test-Infrastruktur
#
# Vollstaendige Integration-Test Umgebung fuer CI/CD Pipeline.
# Startet alle Services isoliert fuer Integration-Tests.
#
# Verwendung:
#   docker compose -f docker-compose.test.yml up -d
#   docker compose -f docker-compose.test.yml down -v
#
# Verbindungen:
#   PostgreSQL: localhost:55432 (breakpilot_test/breakpilot/breakpilot)
#   Valkey/Redis: localhost:56379
#   Consent Service: localhost:58081
#   Backend: localhost:58000
#   Mailpit Web: localhost:58025
#   Mailpit SMTP: localhost:51025

version: "3.9"

services:
  # ========================================
  # Datenbank-Services
  # ========================================

  postgres-test:
    image: postgres:16-alpine
    container_name: breakpilot-postgres-test
    environment:
      POSTGRES_DB: breakpilot_test
      POSTGRES_USER: breakpilot
      POSTGRES_PASSWORD: breakpilot_test
    ports:
      - "55432:5432"
    volumes:
      - postgres_test_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U breakpilot -d breakpilot_test"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - breakpilot-test-network
    restart: unless-stopped

  valkey-test:
    image: valkey/valkey:7-alpine
    container_name: breakpilot-valkey-test
    ports:
      - "56379:6379"
    healthcheck:
      test: ["CMD", "valkey-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - breakpilot-test-network
    restart: unless-stopped

  # ========================================
  # Application Services
  # ========================================

  # Consent Service (Go)
  consent-service-test:
    build:
      context: ./consent-service
      dockerfile: Dockerfile
    container_name: breakpilot-consent-service-test
    ports:
      - "58081:8081"
    depends_on:
      postgres-test:
        condition: service_healthy
      valkey-test:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:8081/health"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    environment:
      - DATABASE_URL=postgres://breakpilot:breakpilot_test@postgres-test:5432/breakpilot_test
      - VALKEY_URL=redis://valkey-test:6379
      - REDIS_URL=redis://valkey-test:6379
      - JWT_SECRET=test-jwt-secret-for-integration-tests
      - ENVIRONMENT=test
      - LOG_LEVEL=debug
    networks:
      - breakpilot-test-network
    restart: unless-stopped

  # Backend (Python FastAPI)
  backend-test:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: breakpilot-backend-test
    ports:
      - "58000:8000"
    depends_on:
      postgres-test:
        condition: service_healthy
      valkey-test:
        condition: service_healthy
      consent-service-test:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 45s
    environment:
      - DATABASE_URL=postgresql://breakpilot:breakpilot_test@postgres-test:5432/breakpilot_test
      - CONSENT_SERVICE_URL=http://consent-service-test:8081
      - VALKEY_URL=redis://valkey-test:6379
      - REDIS_URL=redis://valkey-test:6379
      - JWT_SECRET=test-jwt-secret-for-integration-tests
      - ENVIRONMENT=test
      - SMTP_HOST=mailpit-test
      - SMTP_PORT=1025
      - SKIP_INTEGRATION_TESTS=false
    networks:
      - breakpilot-test-network
    restart: unless-stopped

  # ========================================
  # Development/Testing Tools
  # ========================================

  # Mailpit (E-Mail Testing)
  mailpit-test:
    image: axllent/mailpit:latest
    container_name: breakpilot-mailpit-test
    ports:
      - "58025:8025"   # Web UI
      - "51025:1025"   # SMTP
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:8025/api/v1/info"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - breakpilot-test-network
    restart: unless-stopped

networks:
  breakpilot-test-network:
    driver: bridge

volumes:
  postgres_test_data:
