services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: botdb
      POSTGRES_USER: bot
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-botpass}
    volumes:
      - ./db/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U bot -d botdb"]
      interval: 5s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  bot:
    build:
      context: .
    volumes:
      - ./db:/db
    env_file:
      - .env
    environment:
      TZ: Europe/Moscow
      DATABASE_URL: postgresql://bot:${POSTGRES_PASSWORD:-botpass}@postgres:5432/botdb
      POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json
      NUDE_HISTORY_PATH: /db/nude_history.json
      LLAMA_API_URL: ${LLAMA_API_URL:-https://mirror.porno4free.ru/zovos-ai/}
      LLAMA_FORCE_DISABLE_THINKING: ${LLAMA_FORCE_DISABLE_THINKING:-0}
      LLAMA_LOG_THINKING: ${LLAMA_LOG_THINKING:-1}
    depends_on:
      postgres:
        condition: service_healthy
    init: true
    restart: unless-stopped

  webapp-api:
    build:
      context: .
      dockerfile: Dockerfile.api
    volumes:
      - ./db:/db
    env_file:
      - .env
    environment:
      TZ: Europe/Moscow
      DATABASE_URL: postgresql://bot:${POSTGRES_PASSWORD:-botpass}@postgres:5432/botdb
      POLYCHAETSI_STATS_PATH: /db/polychaetsi_stats.json
      NUDE_HISTORY_PATH: /db/nude_history.json
      API_PORT: "8080"
      LLAMA_API_URL: ${LLAMA_API_URL:-https://mirror.porno4free.ru/zovos-ai/}
      LLAMA_FORCE_DISABLE_THINKING: ${LLAMA_FORCE_DISABLE_THINKING:-0}
      LLAMA_LOG_THINKING: ${LLAMA_LOG_THINKING:-1}
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  webapp-frontend:
    build:
      context: ./webapp/frontend
    ports:
      - "37.27.192.132:${WEBAPP_HTTP_PORT:-80}:80"
      - "37.27.192.132:${WEBAPP_HTTPS_PORT:-443}:443"
    environment:
      APP_DOMAIN: ${APP_DOMAIN:-}
      APP_WWW_DOMAIN: ${APP_WWW_DOMAIN:-}
      ACME_EMAIL: ${ACME_EMAIL:-}
      CERTBOT_STAGING: ${CERTBOT_STAGING:-0}
      CERTBOT_RENEW_INTERVAL: ${CERTBOT_RENEW_INTERVAL:-12h}
    volumes:
      - certbot_etc:/etc/letsencrypt
      - certbot_www:/var/www/certbot
    depends_on:
      - webapp-api
    restart: unless-stopped

volumes:
  postgres_data:
  certbot_etc:
  certbot_www:
