services:
  lavalink:
    image: fredboat/lavalink:latest
    container_name: lavalink
    restart: unless-stopped
    networks:
      - bot-network
    ports:
      - "2333:2333"
    environment:
      - LAVALINK_SERVER_PASSWORD=${LAVALINK_PASSWORD}
      # Removed LAVALINK_PLUGIN_URLS environment variable
    volumes:
      - ./application.yml:/opt/Lavalink/application.yml:ro,Z
      # Mount local plugins directory into the container
      - ./plugins:/plugins:ro 
    # Add healthcheck to verify Lavalink is ready
    healthcheck:
      # Use CMD-SHELL to allow environment variable expansion for the password
      test: ["CMD-SHELL", "curl -H \"Authorization: $$LAVALINK_SERVER_PASSWORD\" -f http://localhost:2333/version || exit 1"]
      interval: 10s # Increased interval slightly
      timeout: 5s
      retries: 5
      start_period: 15s # Give Lavalink time to start up initially
    # Removed command override, will use default image entrypoint

  bot:
    build: .
    container_name: discord-music-bot
    restart: unless-stopped
    networks:
      - bot-network
    env_file:
      - .env
    environment:
      LAVALINK_HOST: lavalink
      LAVALINK_PORT: 2333
      LAVALINK_PASSWORD: ${LAVALINK_PASSWORD}
    # Update depends_on to wait for healthcheck
    depends_on:
      lavalink:
        condition: service_healthy

networks:
  bot-network:
    driver: bridge
