version: '3.8'

services:
  bridge-api:
    build:
      context: .
      dockerfile: Dockerfile
    image: aiva-bridge-api:latest
    container_name: aiva-bridge-api
    ports:
      - "${API_PORT:-8000}:8000"
    environment:
      - DATABASE_URL=${DATABASE_URL}
      - TELNYX_API_KEY=${TELNYX_API_KEY}
      - TELNYX_ASSISTANT_ID=${TELNYX_ASSISTANT_ID}
      - AIVA_PHONE_NUMBER=${AIVA_PHONE_NUMBER}
      - API_KEY=${API_KEY}
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
    env_file:
      - .env
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "-H", "X-API-Key: ${API_KEY}", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    networks:
      - aiva-network

  poller:
    build:
      context: .
      dockerfile: Dockerfile.poller
    image: aiva-poller:latest
    container_name: aiva-poller
    environment:
      - DATABASE_URL=${DATABASE_URL}
      - API_KEY=${API_KEY}
      - POLL_INTERVAL_SECONDS=${POLL_INTERVAL_SECONDS:-5}
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
    env_file:
      - .env
    restart: unless-stopped
    depends_on:
      bridge-api:
        condition: service_healthy
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
    networks:
      - aiva-network

networks:
  aiva-network:
    driver: bridge