version: '3.8'

services:
  postgres:
    image: postgis/postgis:14-3.2
    container_name: chatdate_postgres
    environment:
      POSTGRES_DB: chatdate
      POSTGRES_USER: chatdate_user
      POSTGRES_PASSWORD: ${DB_PASSWORD:-changeme}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - chatdate_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U chatdate_user -d chatdate"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: chatdate_redis
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    ports:
      - "6379:6379"
    networks:
      - chatdate_network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  bot:
    build: .
    container_name: chatdate_bot
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      BOT_TOKEN: ${BOT_TOKEN}
      DATABASE_URL: postgresql+asyncpg://chatdate_user:${DB_PASSWORD:-changeme}@postgres:5432/chatdate
      REDIS_URL: redis://redis:6379/0
      SECRET_KEY: ${SECRET_KEY}
      WEBHOOK_URL: ${WEBHOOK_URL}
      ADMIN_USER_IDS: ${ADMIN_USER_IDS}
    volumes:
      - ./logs:/app/logs
    networks:
      - chatdate_network
    restart: unless-stopped

  # Optional: Nginx for webhook mode
  nginx:
    image: nginx:alpine
    container_name: chatdate_nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl:/etc/nginx/ssl:ro
    ports:
      - "80:80"
      - "443:443"
    networks:
      - chatdate_network
    depends_on:
      - bot
    profiles:
      - webhook

volumes:
  postgres_data:
  redis_data:

networks:
  chatdate_network:
    driver: bridge
