services:
  evolution-api:
    build: .
    container_name: evolution_api
    restart: always
    ports:
      - "8080:8080"
    environment:
      # Configurações do PostgreSQL
      DATABASE_ENABLED: "${DATABASE_ENABLED}"
      DATABASE_PROVIDER: "${DATABASE_PROVIDER}"
      DATABASE_CONNECTION_URI: "${DATABASE_CONNECTION_URI}"
      DATABASE_CONNECTION_CLIENT_NAME: "${DATABASE_CONNECTION_CLIENT_NAME}"
      DATABASE_SAVE_DATA_INSTANCE: "${DATABASE_SAVE_DATA_INSTANCE}"
      DATABASE_SAVE_DATA_NEW_MESSAGE: "${DATABASE_SAVE_DATA_NEW_MESSAGE}"
      DATABASE_SAVE_MESSAGE_UPDATE: "${DATABASE_SAVE_MESSAGE_UPDATE}"
      DATABASE_SAVE_DATA_CONTACTS: "${DATABASE_SAVE_DATA_CONTACTS}"
      DATABASE_SAVE_DATA_CHATS: "${DATABASE_SAVE_DATA_CHATS}"
      DATABASE_SAVE_DATA_LABELS: "${DATABASE_SAVE_DATA_LABELS}"
      DATABASE_SAVE_DATA_HISTORIC: "${DATABASE_SAVE_DATA_HISTORIC}"
      CONFIG_SESSION_PHONE_VERSION: "${CONFIG_SESSION_PHONE_VERSION}"

      # Configurações do Redis
      CACHE_REDIS_ENABLED: "${CACHE_REDIS_ENABLED}"
      CACHE_REDIS_URI: "${CACHE_REDIS_URI}"
      CACHE_REDIS_PREFIX_KEY: "${CACHE_REDIS_PREFIX_KEY}"
      CACHE_REDIS_SAVE_INSTANCES: "${CACHE_REDIS_SAVE_INSTANCES}"
      CACHE_LOCAL_ENABLED: "${CACHE_LOCAL_ENABLED}"

      # Chave de autenticação da API
      AUTHENTICATION_API_KEY: "${AUTHENTICATION_API_KEY}"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  redis:
    image: redis:7
    container_name: evolution_redis
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  postgres:
    image: postgres:14
    container_name: evolution_postgres
    restart: always
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: "${POSTGRES_USER}"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
      POSTGRES_DB: "${POSTGRES_DB}"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  redis_data:
  postgres_data:
