#!/usr/bin/env bash

module_description() { printf "Install PipeWire audio tools\n"; }
module_required() { return 1; }
module_should_skip() { return 1; }
module_prereqs() { return 0; }

module_main() {
  log_section "PipeWire Audio Tools"

  local packages=(
    pipewire
    pipewire-pulse
    pipewire-alsa
    pipewire-jack
    wireplumber
    pavucontrol
    helvum
    easyeffects
  )

  local to_install=()
  local pkg

  for pkg in "${packages[@]}"; do
    if pacman -Si "$pkg" >/dev/null 2>&1 && ! is_package_installed "$pkg"; then
      to_install+=("$pkg")
    fi
  done

  if ((${#to_install[@]})); then
    log_info "Installing PipeWire tools: ${to_install[*]}"
    install_pacman "${to_install[@]}"
    log_success "PipeWire tools installed"
  else
    log_info "All PipeWire tools already installed"
  fi

  if have systemctl; then
    systemctl --user enable --now pipewire pipewire-pulse wireplumber 2>/dev/null || true
    log_info "PipeWire services enabled"
  fi
}
