# BreakPilot Content Service Stack
# Usage: docker-compose -f docker-compose.yml -f docker-compose.content.yml up -d

services:
  # MinIO Object Storage (S3-compatible)
  minio:
    image: minio/minio:latest
    container_name: breakpilot-pwa-minio
    ports:
      - "9000:9000"      # API
      - "9001:9001"      # Console
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin123
    command: server /data --console-address ":9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3
    networks:
      - breakpilot-pwa-network
    restart: unless-stopped

  # Content Service Database (separate from main DB)
  content-db:
    image: postgres:16-alpine
    container_name: breakpilot-pwa-content-db
    ports:
      - "5433:5432"
    environment:
      POSTGRES_USER: breakpilot
      POSTGRES_PASSWORD: breakpilot123
      POSTGRES_DB: breakpilot_content
    volumes:
      - content_db_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U breakpilot -d breakpilot_content"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - breakpilot-pwa-network
    restart: unless-stopped

  # Content Service API
  content-service:
    build:
      context: ./backend/content_service
      dockerfile: Dockerfile
    container_name: breakpilot-pwa-content-service
    ports:
      - "8002:8002"
    environment:
      - CONTENT_DB_URL=postgresql://breakpilot:breakpilot123@content-db:5432/breakpilot_content
      - MINIO_ENDPOINT=minio:9000
      - MINIO_ACCESS_KEY=minioadmin
      - MINIO_SECRET_KEY=minioadmin123
      - MINIO_SECURE=false
      - MINIO_BUCKET=breakpilot-content
      - CONSENT_SERVICE_URL=http://consent-service:8081
      - JWT_SECRET=${JWT_SECRET:-your-super-secret-jwt-key-change-in-production}
      - MATRIX_HOMESERVER=${MATRIX_HOMESERVER:-http://synapse:8008}
      - MATRIX_ACCESS_TOKEN=${MATRIX_ACCESS_TOKEN:-}
    depends_on:
      content-db:
        condition: service_healthy
      minio:
        condition: service_healthy
    networks:
      - breakpilot-pwa-network
    restart: unless-stopped

  # H5P Interactive Content Service
  h5p-service:
    build:
      context: ./h5p-service
      dockerfile: Dockerfile
    container_name: breakpilot-pwa-h5p
    ports:
      - "8003:8080"
    environment:
      - H5P_STORAGE_PATH=/h5p-content
      - CONTENT_SERVICE_URL=http://content-service:8002
    volumes:
      - h5p_content:/h5p-content
    networks:
      - breakpilot-pwa-network
    restart: unless-stopped

  # AI Content Generator Service
  ai-content-generator:
    build:
      context: ./ai-content-generator
      dockerfile: Dockerfile
    container_name: breakpilot-pwa-ai-generator
    ports:
      - "8004:8004"
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - YOUTUBE_API_KEY=${YOUTUBE_API_KEY:-}
      - H5P_SERVICE_URL=http://h5p-service:8080
      - CONTENT_SERVICE_URL=http://content-service:8002
      - SERVICE_HOST=0.0.0.0
      - SERVICE_PORT=8004
      - MAX_UPLOAD_SIZE=10485760
      - MAX_CONCURRENT_JOBS=5
      - JOB_TIMEOUT=300
    volumes:
      - ai_generator_temp:/app/temp
      - ai_generator_uploads:/app/uploads
    depends_on:
      - h5p-service
      - content-service
    networks:
      - breakpilot-pwa-network
    restart: unless-stopped

volumes:
  minio_data:
    driver: local
  content_db_data:
    driver: local
  h5p_content:
    driver: local
  ai_generator_temp:
    driver: local
  ai_generator_uploads:
    driver: local

networks:
  breakpilot-pwa-network:
    external: true
