version: "3.9"

# Local development stack for indonesia-civic-stack.
# Each module runs as its own service so they can be started independently.
#
# Usage:
#   docker compose up bpom          # start a single module
#   docker compose up                # start all modules
#   docker compose run --rm test     # run the test suite

x-module-defaults: &module-defaults
  build:
    context: .
  environment:
    - PROXY_URL=${PROXY_URL:-}
    - LOG_LEVEL=${LOG_LEVEL:-INFO}
  restart: unless-stopped
  networks:
    - civic

services:
  # ── Phase 1 modules ──────────────────────────────────────────────

  bpom:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/bpom/Dockerfile
    ports:
      - "8001:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=bpom

  bpjph:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/bpjph/Dockerfile
    ports:
      - "8002:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=bpjph

  ahu:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/ahu/Dockerfile
    ports:
      - "8003:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=ahu

  # ── Phase 2 modules ──────────────────────────────────────────────

  kpu:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/kpu/Dockerfile
    ports:
      - "8004:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=kpu

  ojk:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/ojk/Dockerfile
    ports:
      - "8005:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=ojk

  oss-nib:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/oss-nib/Dockerfile
    ports:
      - "8006:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=oss_nib

  lpse:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/lpse/Dockerfile
    ports:
      - "8007:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=lpse

  # ── Phase 3 modules ──────────────────────────────────────────────

  lhkpn:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/lhkpn/Dockerfile
    ports:
      - "8008:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
      - MODULE=lhkpn

  bps:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/bps/Dockerfile
    ports:
      - "8009:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - BPS_API_KEY=${BPS_API_KEY:-}
      - MODULE=bps

  bmkg:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/bmkg/Dockerfile
    ports:
      - "8010:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=bmkg

  simbg:
    <<: *module-defaults
    build:
      context: .
      dockerfile: modules/simbg/Dockerfile
    ports:
      - "8011:8000"
    environment:
      - PROXY_URL=${PROXY_URL:-}
      - MODULE=simbg

  # ── Test runner ──────────────────────────────────────────────────

  test:
    build:
      context: .
    command: python -m pytest tests/ -v --tb=short
    environment:
      - PYTHONPATH=/app
    volumes:
      - .:/app
    networks:
      - civic
    profiles:
      - test

networks:
  civic:
    driver: bridge
