version: '3.8'

services:
  redis:
    image: redis:7-alpine
    container_name: basura-redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    restart: unless-stopped
    networks:
      - basura-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3

  api:
    build: .
    container_name: basura-backend
    ports:
      - "0.0.0.0:8000:8000"
    environment:
      - SECRET_KEY=${SECRET_KEY:-dev-secret-key-change-in-production}
      - DATABASE_PATH=/data/basura.db
      - DEBUG=${DEBUG:-true}
      - SIM_TICK_SECONDS=${SIM_TICK_SECONDS:-10}
      - SIM_ETA_ALERT_MINUTES=${SIM_ETA_ALERT_MINUTES:-10}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_DB=0
      - CACHE_ENABLED=${CACHE_ENABLED:-true}
      - CACHE_TTL_ETA=${CACHE_TTL_ETA:-30}
      - CACHE_TTL_ADDRESSES=${CACHE_TTL_ADDRESSES:-300}
      - CACHE_TTL_GUIDE=${CACHE_TTL_GUIDE:-86400}
    volumes:
      - ./data:/data
      - ./logs:/app/logs
    depends_on:
      redis:
        condition: service_healthy
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    networks:
      - basura-network

networks:
  basura-network:
    driver: bridge

volumes:
  redis-data: