services:
  # PostgreSQL Database
  db:
    image: postgres:16-alpine
    container_name: qrmaster-db-dev
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_INITDB_ARGS: "-E UTF8 --locale=en_US.utf8"
    ports:
      - "5435:5432"
    volumes:
      - dbdata_dev:/var/lib/postgresql/data
      - ./docker/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres -d qrmaster" ]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - qrmaster-network

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

  # Adminer - Database Management UI
  adminer:
    image: adminer:latest
    container_name: qrmaster-adminer-dev
    restart: unless-stopped
    ports:
      - "8081:8080"
    environment:
      ADMINER_DEFAULT_SERVER: db
      ADMINER_DESIGN: pepa-linha
    depends_on:
      - db
    networks:
      - qrmaster-network

volumes:
  dbdata_dev:
    driver: local
  redisdata_dev:
    driver: local

networks:
  qrmaster-network:
    driver: bridge
