services:
  # ── Required environment variables (see .env.example) ───────────────────────
  # APP_BOLT_URL, USER_NEO4J, PASSWORD_NEO4J — Neo4j connection
  # SUPABASE_URL, SERVICE_ROLE_KEY — Supabase project
  # REDIS_HOST, REDIS_PORT, REDIS_PASSWORD — Redis (optional auth)
  # FASTAPI_SECRET_KEY, ADMIN_EMAIL — API config
  redis-dev:
    image: redis:7-alpine
    container_name: cc-redis-dev
    ports:
      - "16379:6379"
    volumes:
      - redis-dev-data:/data
    command: redis-server --appendonly yes
    networks:
      - kevlarai-network
    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      interval: 5s
      timeout: 3s
      retries: 5

  init:
    image: cc-api-dev:latest
    container_name: api-init-dev
    env_file:
      - .env.dev
    environment:
      - REDIS_HOST=redis-dev
      - RUN_INIT=true
      - INIT_MODE=${INIT_MODE:-infra}
      - INIT_ONLY=true
    command: ["./docker-entrypoint.sh", "init-only"]
    depends_on:
      redis-dev:
        condition: service_healthy
    networks:
      - kevlarai-network
    profiles:
      - init

  backend-dev:
    container_name: cc-api-dev
    image: cc-api-dev:latest
    env_file:
      - .env.dev
    environment:
      - REDIS_HOST=redis-dev
      - REDIS_DB_DEV=0
      - BACKEND_DEV_MODE=true
      - APP_ENV=development
      - ENVIRONMENT=development
      - START_MODE=dev
      - CC_COMPOSE_PROJECT=api-dev
      - CC_COMPOSE_SERVICE=backend-dev
      - RUN_INIT=false
      - INIT_MODE=infra
    ports:
      - "18000:8000"
    depends_on:
      redis-dev:
        condition: service_healthy
    networks:
      - kevlarai-network
    restart: unless-stopped

  backend-test:
    image: cc-api-dev:latest
    env_file:
      - .env.dev
    environment:
      - REDIS_HOST=redis-dev
      - REDIS_DB_DEV=0
      - BACKEND_DEV_MODE=true
      - APP_ENV=development
      - ENVIRONMENT=development
      - START_MODE=dev
      - CC_COMPOSE_PROJECT=api-dev
      - CC_COMPOSE_SERVICE=backend-test
      - API_HEALTH_URL=http://192.168.0.64:18000/health
    depends_on:
      redis-dev:
        condition: service_healthy
    networks:
      - kevlarai-network
    entrypoint: ["python", "-m", "pytest"]
    command: ["-q", "tests"]
    profiles:
      - test

volumes:
  redis-dev-data:

networks:
  kevlarai-network:
    external: true
    name: kevlarai-network
