services:

  # ── PostgreSQL ──────────────────────────────────────────────────────────────
  postgres:
    image: postgres:16-bookworm
    restart: unless-stopped
    environment:
      POSTGRES_DB: archivmail
      POSTGRES_USER: archivmail
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U archivmail"]
      interval: 10s
      timeout: 5s
      retries: 5

  # ── Go Backend ──────────────────────────────────────────────────────────────
  archivmail:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - /etc/archivmail:/etc/archivmail:ro
      - archivmail_data:/var/archivmail
    ports:
      - "127.0.0.1:8080:8080"   # API (nginx proxied)
      - "2525:2525"              # SMTP BCC
      - "1143:1143"              # IMAP (nginx proxied für TLS)
    environment:
      - TZ=Europe/Berlin

  # ── Next.js Frontend ────────────────────────────────────────────────────────
  archivmail-web:
    build:
      context: .
      dockerfile: Dockerfile.web
    restart: unless-stopped
    depends_on:
      - archivmail
    ports:
      - "127.0.0.1:3000:3000"   # Frontend (nginx proxied)
    environment:
      - NEXT_PUBLIC_API_URL=http://archivmail:8080
      - TZ=Europe/Berlin

volumes:
  postgres_data:
  archivmail_data:
